开发者

iOS OpenGL skewed drawing

So I'm having a bit of a problem with an OpenGL 1.1 skewed drawing. Background: Basically the app is a painting app (some code borrowed from glPaint) in which the user can draw with various colors and point widths. When they exit the drawing screen I use glReadPixels to persist the pixel color data in RGBA format. When they come back to continue drawing I take the color data from disk, put it into a colorPointer and I generate an array of vertices like so:

 typedef struct _vertexStruct{ GLfloat position[2];} vertexStruct;

 vertexStruct vertices[VERTEX_SIZE];

And the loop

GLfloat row = 0.0f;
GLfloat col = 768.0f;

for (int i = 0; i < (768 * 1024); i++) {

    if (row == 1024.0f) {
        col-- ;
        row = 0.0f;
    }
    else {
        row++;
    }


    vertices[i].position[0] =  row; 
    vertices[i].position[1] =  [self bounds].size.height - col;

}

And here are the actual drawing calls:

glVertexPointer(2, GL_FLOAT, sizeof(vertexStruct),&vertices[0].position);
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(pixelData.data), pixelData.data);
glEnableClientState(GL_COLOR_ARRAY);
glDrawArrays(GL_POINTS, 0, VERTEX_SIZE);
glDisableClientState(GL_COLOR_ARRAY);


// Display the buffer
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];

So, the drawing succeeds but it is skewed off to the left of where it should be. I thought that I was compensating for OpenGL(I'm using standard bottom=0,left=0 coord system) --> UIKit coordinate system differences with the

vertices[i].position[开发者_开发百科1] =  [self bounds].size.height - col;

call in the loop but this may just be a naive assumption. Anyone have any clues as to what I'm doing wrong or perhaps what I need to be doing addition to have the drawing appear in the right place?? Thanks in advance!

UPDATE: Solved, I just drew the saved image to a texture (NPOT texture)! If anyone else has worries about drawing NPOT textures, it should work, worked for me at least, with the only caveat being that it's not supported on earlier devices...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜