在draw
我的CCLayer
. 我正在画一些线条并CGPoints
存储在std::vector
. 我已经使用 ccDrawLine 成功绘制了线条。但是,使用时glDrawArray
,什么都没有显示。我已经包含了结果的屏幕截图。正如您在使用 ccDrawnLine 时所看到的,它正确地绘制了线条。有任何想法吗?
[更新] 我使用的是 Cocos2d v2.0,默认情况下它使用 OpenGLES 2.0。
//openGLES
#include <OpenGLES/EAGL.h>
#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>
- (void) draw {
glLineWidth( 3.0f );
//begin and clear
[renderTexture beginWithClear:waveform4F.r g:waveform4F.g b:waveform4F.b a:waveform4F.a];
vector<CGPoint> vertices = bufferQueue.front();
if (WaveformStyleLined) {
for (int i = 1; i < vertices.size(); i++)
ccDrawLine(vertices[i - 1], vertices[i]);
} else {
ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );
kmGLPushMatrix();
glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, sizeof(CGPoint), &vertices[0]);
glDrawArrays(GL_LINES, sizeof(CGPoint), vertices.size());
kmGLPopMatrix();
}
bufferQueue.pop();
[renderTexture end];
}
以下是 my 中的一些CGPoint
s vertices
:
2012-08-18 08:57:49.750 vertices[1]:NSPoint: {1, 48.09375}
2012-08-18 08:57:49.751 vertices[2]:NSPoint: {2, 47.996094}
2012-08-18 08:57:49.752 vertices[3]:NSPoint: {3, 48.046875}
2012-08-18 08:57:49.753 vertices[4]:NSPoint: {4, 48.214844}
2012-08-18 08:57:49.754 vertices[5]:NSPoint: {5, 48.152344}
2012-08-18 08:57:49.755 vertices[6]:NSPoint: {6, 48.035156}
2012-08-18 08:57:49.755 vertices[7]:NSPoint: {7, 48.078125}
2012-08-18 08:57:49.756 vertices[8]:NSPoint: {8, 48.144531}
2012-08-18 08:57:49.757 vertices[9]:NSPoint: {9, 48.0625}
2012-08-18 08:57:49.757 vertices[10]:NSPoint: {10, 48.242188}