Jump to content
  • Advertisement

Archived

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

logout

2d in ogl question

This topic is 5453 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
well, what is happening that is wrong? i.e. where is the quad, and how big is it?

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
thx m8 ...

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


10pts to you !

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!