Skip to main content
gamedev.net
🔒 Locked

coordinates

Started by utr0cks Jan 1, 2004 at 6:00 PM 1 replies 300+ views
Original Post
utr0cks
utr0cks
ok, im making a little 2d game engine using textured quads in opengl. i translate my quads around using glTranslatef(x,y,-10) i always use -10 as my z coordinate i am having trouble figuring out which x, y pixels are visible at a depth of 10. I know about how many through trial and error, but there must be some formula that could tell me also... my gl window setup code is straight from nehe and looks like this...
glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix
	glLoadIdentity();							// Reset The Projection Matrix

	// Calculate The Aspect Ratio Of The Window
	gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

	glMatrixMode(GL_MODELVIEW);						// Select The Modelview Matrix
	glLoadIdentity();							// Reset The Modelview Matrix
}
 
silvermace
silvermace
a 2D game, i must ask why you are using perspective mode...
for 2d, use gluOrtho(...) with this each unit becomes a
pixel eg.

//alwayz 0 for z value in 2d mode
glTranslatef(10, 10, 0);
//translatefs 10 pixels right, and 10 pixels down


get it ?
if you need more help i can show you the code from my old 2d
shooter..

cu.
Irix
tHiSiSbOb
tHiSiSbOb
quote:
Original post by silvermace
a 2D game, i must ask why you are using perspective mode...
for 2d, use gluOrtho(...) with this each unit becomes a
pixel eg.

//alwayz 0 for z value in 2d mode
glTranslatef(10, 10, 0);
//translatefs 10 pixels right, and 10 pixels down


get it ?
if you need more help i can show you the code from my old 2d
shooter..

cu.
Irix


Yea, if you are going to use GL for 2d stuff, you will want to use glOrtho. It just makes it easier to deal with screen coordinates than doing it any other way.
----------------------------------------------------"Plant a tree. Remove a Bush" -A bumper sticker I saw.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.