OpenGL data types

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;}
};

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.

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.

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.

i think you better move this discussion to the beginners forum.

otherwise you might get knackered :smiley:

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 (Yahoo | Mail, Weather, Search, Politics, News, Finance, Sports & Videos)

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

Oh no, do carry on, this is fascinating…especially the bit about doubles never being a bottleneck.

Originally posted by RigidBody:
[b] i think you better move this discussion to the beginners forum.

otherwise you might get knackered :smiley: [/b]
LOOOL :smiley:

And my bad antiknack-attack revenge, even worst to pollute a topic… :slight_smile:

Right, the gang’s all here. You ready jide?

Was just waiting for you to start your engine :stuck_out_tongue:

well, i tried to warn you. no more i can do; i’m out of here.

RigidBody, I just hope we were friendly kidding with knackered nothing more, at least I was.

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.

We’re so dark people we the others.

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…

it’s a typo in zengar’s post. the file is gl.h, not gh.h

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.

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.

but if you use a display list, each vertex will be converted only once, correct?

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.