Archived

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

iDDqD

Units to pixels?

Recommended Posts

Hi... Im trying to create a very simple 2d game, using a bunch of bitmaps for pictures. Each picture is, for example 32x32 pixels big. The question is, how can i create a square that is 32x32 pixels, creating quad using ogl uints doesnt seem to hard, according to the tutorials, but using pixel seems hard to find an article about. Also, how can i tell where the top left corner of the screen is? Well, maybe this question is completly stupid, but i cant figure the answer Thx for reading it through //iDDqD and yes, iddqd is godmode in d00m. The more you know, the more you know that you dont know.

Share this post


Link to post
Share on other sites
Setup orthographic projection

The top-left corner in OpenGL is x=0.0 y=1.0

units to pixels (x): units*screenwidth
units to pixels (y): units*screenheight
pixels to units (x): pixels/screenwidth
pixels to units (y): pixels/screenheight

Share this post


Link to post
Share on other sites
try converting it to a one to one ration using glViewport, and make it 2D with the glOrtho functions.

ie - glViewport(640,480);

My Homepage

Some shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911

Share this post


Link to post
Share on other sites
I figure i would do something like that, allto, dont think i understad

#define TOP 0px
#define LEFT 0px

glLoadIdentity();
glTranslatef(TOP,LEFT);

glBegin(GL_QUADS);
glVertex3f(0px, 0px, 0px);
glVertex3f(32px, 0px, 0px);
glVertex3f(0px, 32px, 0px);
glVertex3f(32px, 32px, 0px);
glEnd();

// px just illustrates that i want to move it pixels

could any1 give me some samplecode and/or tell me the fuctions and what parametes they use that would do something similar to this?

The more you know, the more you know that you dont know.

Share this post


Link to post
Share on other sites

// Set up the viewport to 640x480 for 2d

glViewport(0,0,640,480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f,640.0f,0.0f,480.0f,-10.0f,10.0f);

glMatrixMode(GL_MODELVIEW);
[/source[


My Homepage

Some shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911

Share this post


Link to post
Share on other sites
Thx man, that was exactly what i was trying to achive.
My game is starting to take form now
cheers
-----------------------------------------------------------------

The more you know, the more you know that you dont know.

Share this post


Link to post
Share on other sites