Archived

This topic is now archived and is closed to further replies.

logout

2d in ogl question

Recommended Posts

Okay now i got a window up and running .... i have also changed into 2d mode ( using the code found here : http://www.gamedev.net/community/forums/topic.asp?topic_id=104791 ) I have problems drawing a quad in the top left corner the quad should be 64x64 pixels. ( i also wonder what i need to do in order to manipulate ogl into thinking that 0,0 = the top left corner and max_x && max_y = lower right corner ... current code:
	glBegin(GL_QUADS);
		glColor3ub(255, 0, 0);
        
		glVertex2i(0, 0);
		glVertex2i(0, 64);
        glVertex2i(64, 64);
        glVertex2i(64, 0);

		glEnd();
 
also is there any good books on doing 2d in ogl ?

Share this post


Link to post
Share on other sites
This has to with the point of origin, in OpenGL the origin is, I believe, exactly in the center of the screen. Just like a cartesian coordinate system. You might have thought the point of origin was in the upper-left corner.

Share this post


Link to post
Share on other sites
"glOrtho(0, vPort[2], 0, vPort[3], -1, 1);"

now look up glOrtho:
glOrtho(left, right, bottom, top...

you yourself told opengl that 0,0 is supposed to be bottom left.

Share this post


Link to post
Share on other sites
yeah in case someone wonder what the sulution is
i have updated Dwarf with Axe''s code to create a "correct" 2d viewpoint



void glEnable2D()
{
int vPort[4];
glGetIntegerv(GL_VIEWPORT, vPort);

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

// this line was changed

glOrtho(0, vPort[2], vPort[3], 0, -1, 1);

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

}

[/source]

Share this post


Link to post
Share on other sites