View Full Version : OpenGL data types

Jameson Quave
05-16-2006, 07:56 PM
I'm using visual c++ in a console project and using opengl. What kind of datatype should I be using for my vectors and whatnot? I have been making my own data types because I didn't think it was built in to opengl.. but maybe it is... I don't want to start writing methods for cross-products and whatnot if that's already done for me in OpenGl... this is an example of what im talking about:

struct qVect {
double x;
double y;
double z;
double xn;
double yn;
double zn;
void setPos(double xi, double yi, double zi) { x=xi; y=yi; z=zi;}
void setNorm(double xi, double yi, double zi) { xn=xi; yn=yi; zn=zi;}
void setNorm( qVect normal ) { xn=normal.x; yn=normal.y; zn=normal.z;}
qVect norm(){qVect normal; normal.x = xn; normal.y = yn; normal.z = zn; return normal;}

05-17-2006, 01:12 AM
GL is neither a type library nor a vector math library. All GL datatypes can be found in gh.h if you would care to look at it. If you want to submit data to OpenGL you have to use either vertex arrays or vertex specification operations. This way it is completely up to you how you define your data, GL doesn't care.
And this is hardly an advanced topic, please post things like that in the beginners one.

05-17-2006, 01:24 AM
Most, if not all, OpenGL implementations use 32 bit floats internally. For performance reasons you should prefer floats over doubles in your data structures if the precision is sufficient for your purpose.

05-17-2006, 07:48 AM
Storing your data as floats breaks down if you need to use the utility routines, gluProject and gluUnproject. These assume that you have doubles and would therefore need to convert often. For this reason, I tend toward doubles instead of floats. I've never heard of double to float conversion being the bottleneck in a program.

05-17-2006, 08:06 AM
i think you better move this discussion to the beginners forum.

otherwise you might get knackered :D

05-17-2006, 08:45 AM
You should read the thread "Vertex Array Error", which is just below yours. Read the last 10 replies.

Using double when hw doesn't support it is silly. Write your own version of gluProject and gluUnProject (http://www.mesa3d.org has the source) or use my glhlib (http://www.geocities.com/vmelkon/glhlibrary.html)

I have many version available, including ones using SSE
glhProjectf, glhUnProjectf
glhProjectf_2, glhProjectf_3

05-17-2006, 08:47 AM
Oh no, do carry on, this is fascinating....especially the bit about doubles never being a bottleneck.

05-17-2006, 09:32 AM
Originally posted by RigidBody:
i think you better move this discussion to the beginners forum.

otherwise you might get knackered :D LOOOL :D

And my bad antiknack-attack revenge, even worst to pollute a topic... :)

05-17-2006, 09:54 AM
Right, the gang's all here. You ready jide?

05-17-2006, 10:07 AM
Was just waiting for you to start your engine :p

05-17-2006, 10:51 AM
well, i tried to warn you. no more i can do; i'm out of here.

05-17-2006, 11:53 AM
RigidBody, I just hope we were friendly kidding with knackered nothing more, at least I was.

05-17-2006, 12:24 PM
no need to tell me. i am one of two or three people in this forum who know that knackered is the only guy around here with a good sense of humour.

05-17-2006, 01:54 PM
We're so dark people we the others.

Jameson Quave
05-17-2006, 02:33 PM
Okay I didn't know about the file gh.h containing GL's data types.. so thanks for that... except that the file doesn't seem to exist on my computer..

05-17-2006, 02:48 PM
it's a typo in zengar's post. the file is gl.h, not gh.h

Jameson Quave
05-17-2006, 02:57 PM
Ah that would explain it, I thought I was missing part of the installation. Thanks for the help.. I would move this but it doesn't allow me, sorry for posting in the wrong section.
Also... I couldn't help but notice

typedef double GLdouble;

WINGDIAPI void APIENTRY glVertex3d (GLdouble x, GLdouble y, GLdouble z);Seems they used double as well.

05-18-2006, 05:15 AM
yes, you can specify vertex data using doubles, nobody's saying you can't. But consider that most implementations don't support doubles in hardware, so when you submit an array of double precision vertices, it's possible the driver will have to convert them to floats each time you submit them, but also keep a copy of the original floats in case you want to read them back. You've lost memory and upload performance, and gained nothing at all.

05-18-2006, 05:25 AM
but if you use a display list, each vertex will be converted only once, correct?

05-18-2006, 05:50 AM
Originally posted by RigidBody:
but if you use a display list, each vertex will be converted only once, correct? It is likely that only one coversion will take place however this is not guaranteed and the driver may choose to do the conversion each time the list is called.

05-18-2006, 09:14 PM
my understanding is no current consumer cards support double thus u gain absolutly no precision by using them, but lose performance/memory.
its like asking for a RGBA16 texture (and the card supports RGBA8 max) in which case it ignores the 16 + acts like u asked for a RGBA8 texture