2d in ogl question

Started by
7 comments, last by logout 20 years, 8 months ago
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 ?
Advertisement
anybody ?

come on folks ! give it to me !
well, what is happening that is wrong? i.e. where is the quad, and how big is it?
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
The quad is in the lower left conrner.
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.
osu!
"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.
f@dzhttp://festini.device-zero.de
thx m8 ...

dint know that i could change it like that ! !
*thot it would mess up ogl*


10pts to you !
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]
A much better way indeed. Good job! =)
----------[Development Journal]

This topic is closed to new replies.

Advertisement