Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: OpenGL ES 2D drawing problem

  1. #1
    Newbie Newbie
    Join Date
    Jul 2013
    Posts
    1

    OpenGL ES 2D drawing problem

    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 ?

    Code :
    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;
    }

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Posts
    751
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •