Skip to main content
GameDev.net gamedev.net
🔒 Locked

Units to pixels?

Started by iDDqD Sep 2, 2003 at 10:09 AM 4 replies 600+ views
Original Post
iDDqD
iDDqD
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.
The more you know, the more you know that you dont know.
noVum
noVum
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
Julio
Julio
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
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
iDDqD
iDDqD
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.
The more you know, the more you know that you dont know.
Julio
Julio

// 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
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
iDDqD
iDDqD
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.
The more you know, the more you know that you dont know.

Topic Locked

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

Sign in to reply to this topic.