PDA

View Full Version : OpenGL ES 2D drawing problem



przemek79
07-09-2013, 09:49 AM
Hello. I trying to learn OpenGl ES on Tizen SDK. I want make 2D game. When I start from the sample , in 3D everything displays well. But I am getting black screen when I change glFrustumf to glOrthox and changing vertices.

This is my code. Can anyone check this what is wrong ?


bool
GlRendererTemplate::InitializeGl(void)
{
glShadeModel(GL_SMOOTH);
glViewport(0, 0, GetTargetControlWidth(), GetTargetControlHeight());

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthox(0, GetTargetControlWidth(), GetTargetControlHeight(), 0, -1, 1);

glDisable(GL_DEPTH_TEST);

glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);

load_textures();

return true;
}


bool
GlRendererTemplate::Draw(void)
{
static const GLfloat vertices[] =
{
50,50,
650,50,
50,1200,
650,1200
};

static const GLfloat tex_vertices[] =
{
1,1,
0,1,
1,0,
0,0
};

static const unsigned short indexBuffer[] =
{
0, 1,2,3
};

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glEnable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, vertices);

glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2,GL_FLOAT,0, tex_vertices);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex[0]);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, &indexBuffer[0]);

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_2D);

glFlush();

return true;
}

carsten neumann
07-09-2013, 10:35 AM
I don't see anything obviously wrong. A common error is that your scene is simply not inside the view frustum. With your projection setup (and ignoring additional view transforms, since they are not shown) you'd only see objects that have a positive x/y location (between 0 and screen size) and z coordinate between -1 and 1.