Skip to main content
gamedev.net
🔒 Locked

glVertex Explanation?

Started by fmwyso Dec 29, 2008 at 9:31 PM 6 replies 1.1k views
Original Post
fmwyso
fmwyso
I already found an explanation for the glColor and now I'm using glColor3ub and exceptionally happy now ^_^... I'm making a very simple thing right now which is 2-d and is basically just for fun (more for challenge :P). So, I don't need the z coord so now I'm using glVertex2f, but I have NO idea what the 1.0 actually means... Is there any way to have it be in pixels, if not could someone explains what the floats are written in? As in... What measurement of size are the floats in? Pixels / inches / % of screen etc.? Thanks for your time, fmwyso (I looked in google a couple times and couldn't find anything at all so I posted here by the way... Sorry if there is one already >,<).
scwizzo
scwizzo
The units are in whatever you want them to be. They are not in pixels, although you could make them be in pixels. But it is probably easier to just render things based on a unit size then a pixel.

example, I have a 3D model of a dwarf I downloaded from somewhere, and I made the max height be 9.xxx, now what does this height of 9.xxx mean? Means whatever I want it to. 9 cm, mm, feet, inches, meters, etc.
/ Visual Studios 2010 / Codeblocks 10.05 / Windows 7 / Ubuntu 10.10 / - I might be wrong
KulSeran
KulSeran
since you are doing 2d work, just setup your glViewport() to be the resolution you want in pixels (this does NOT have to match the resolution of the window, but matching the aspect ratio you want is a good idea)
then numbers put into glVertex2f() will directly match coordinates inside that viewport (assuming orthographic projection is setup right too)
fmwyso
fmwyso
Hmm... Thanks for the answers but they aren't exactly what I'm looking to find out...

(Just so ya know, I'm using the default code from the NeHe site for everything except my draw function which I re-wrote completely.)

What I am wondering is how I can measure where my pixels should be... For example, How would I find out what float spot the 4 corners of my window are at... All I know atm is that it is 640 x 480, so what is 640 in float so I know my dimensions etc.?
leiavoia
leiavoia
I think KulSeran already answered your question. Best to reread it one more time.

In OpenGL, the units are completely, totally arbitrary. For convenience and ease of mind, it helps to make the viewport (the screen) match the modeling space pixel-to-pixel, since that's generally how we think of 2D screen space anyway.

A "float" is just a number with a decimal point in it. They work differently than integers, obviously, but 1.0 (float) is the same as 1 (integer). It's also the same as 1.00 and 1.0000000000. See? One is one is one. But one what? It's whatever you want! But in your case you want it to be pixels, so see the previous paragraph.

You'll want to keep everything in floats because at some point you are going to have an object move around on the screen in increments finer than 1-pixel per frame (it sounds dumb right now, i know, but trust me). Also keep in mind that you can use glVertex3i for integers instead of using floats if you really want to.
SimonForsman
SimonForsman
Quote:
Original post by fmwyso
Hmm... Thanks for the answers but they aren't exactly what I'm looking to find out...

(Just so ya know, I'm using the default code from the NeHe site for everything except my draw function which I re-wrote completely.)

What I am wondering is how I can measure where my pixels should be... For example, How would I find out what float spot the 4 corners of my window are at... All I know atm is that it is 640 x 480, so what is 640 in float so I know my dimensions etc.?



Take a look at Lesson 21 on NeHe, it covers orthographic projection amongst other things, or you could read this
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
kittycat768
kittycat768
If you are using a 2D projection keep in mind that the alignment will be off by one pixel if you don't feed the Ortho functions your width and height minus 1. I discovered this via my own adventures in 2d opengl tinkering.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------I once read that World of Warcraft is poor fishing simulator. I don't know about you but I catch a lot more fish in World of Warcraft than I do in real life.
swiftcoder
swiftcoder
Quote:
Original post by fmwyso
(Just so ya know, I'm using the default code from the NeHe site for everything except my draw function which I re-wrote completely.)
Before you completely rewrite that draw function, consider throwing it away entirely. Modern OpenGL programs should not use immediate mode (glVertex*, glColor*, ...). Instead they should use vertex arrays and vertex buffer objects, along with glDrawElements/glDrawArrays.

You can pick up the basics of this in the new NeHe lessons, although they have not yet progressed to advanced topics.
Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Topic Locked

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

Sign in to reply to this topic.