• Announcements

Archived

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

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 on other sites
anybody ?

come on folks ! give it to me !

Share on other sites
well, what is happening that is wrong? i.e. where is the quad, and how big is it?

Share on other sites
The quad is in the lower left conrner.

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 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 on other sites
thx m8 ...

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

10pts to you !

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 on other sites
A much better way indeed. Good job! =)

• Partner Spotlight

• Forum Statistics

• Total Topics
627646
• Total Posts
2978383

• 10
• 12
• 22
• 13
• 33