Talk About Network

Google





Graphics > OpenGL 3D API > Re: drawing ele...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 10 Topic 4760 of 5061
Post > Topic >>

Re: drawing elements: why only one index buffer

by Wolfgang Draxinger <wdraxinger@[EMAIL PROTECTED] > May 22, 2008 at 02:55 AM

sheam wrote:

> So I guess, my best bet would be interleaved arrays.=20
> Unfortunately, in order to use interleaved arrays, it looks
> like I will have to strip out
> color, as there is no T2F_C4UB_N3F_V3F.  Which seems like kind
> of an odd
> omission to me.  I know of atleast two consoles which pack this
> way.
> Yet I don't know of one that does T2F_C4F_N3F_V3F.  Oh, well, I
> don't actually need color in most instances, so I will just
> make a vertex variant without it, and use T2F_N3F_V3F.

You're not forced to use glInterleavedArrays.

#include <stdint.h>
typedef uint32_t colorRGBA;
typedef struct Vector3d { GLfloat x,y,z; } Vector3d;
typedev struct Vector2d { GLfloat u,v; } Vector2d;
typedef struct Vertex
{
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Vector2d texcoord;
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0colorRGBA color;
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Vector3d normal;
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Vector3d coord;
} Vertex;

void setVAPointer(Vertex *V)
{
        glVertexPointer(3, GL_FLOAT, sizeof(Vertex), &(V->coord));
        glNormalPointer(GL_FLOAT, sizeof(Vertex), &(V->normal));
        glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex),
&(V->colorRGBA));
        glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &(V->texcoord));=

}

In fact in most implementations glInterleavedArrays is just a
shorthand for a arrangement of these calls.

Wolfgang Draxinger

P.S.: Note, that it's impossible in pure C/C++ without extensions
to exactly define the memory layout of structs. Thank good most
compilers provide pragmas/extensions to do this. Given this fact
I'm rather surprised, that there are almost no bugs due to this.
I'm thinking about using pointers to structs in ABIs. E.g. a lot
of stuff in Linux depends on structs passed around. But almost
none of the system include files explicitly define the memory
layout using pragmas, or compiler extensions.

After years of programming I came to realize this only lately,
when working on the compiler for the programming language I
designed. There are so many things we take for granted, until we
dig deep into the inner structure of things...

So the above code will probably work in 99.9%, but there might be
situations where it won't.

--=20
E-Mail address works, Jabber: hexarith@[EMAIL PROTECTED]
 ICQ: 134682867
 




 10 Posts in Topic:
drawing elements: why only one index buffer
sheam <shea08@[EMAIL P  2008-05-21 02:38:47 
Re: drawing elements: why only one index buffer
fungus <openglMYSOCKS@  2008-05-20 19:52:38 
Re: drawing elements: why only one index buffer
sheam <shea08@[EMAIL P  2008-05-21 23:24:03 
Re: drawing elements: why only one index buffer
Wolfgang Draxinger <wd  2008-05-21 10:49:27 
Re: drawing elements: why only one index buffer
sheam <shea08@[EMAIL P  2008-05-21 23:32:01 
Re: drawing elements: why only one index buffer
Wolfgang Draxinger <wd  2008-05-22 02:55:23 
Re: drawing elements: why only one index buffer
sheam <shea08@[EMAIL P  2008-05-22 04:21:26 
Re: drawing elements: why only one index buffer
Wolfgang Draxinger <wd  2008-05-23 01:20:32 
Re: drawing elements: why only one index buffer
"jbwest" <jb  2008-05-21 17:55:50 
Re: drawing elements: why only one index buffer
fungus <openglMYSOCKS@  2008-05-21 17:58:30 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
localhost-V2008-12-19 Wed Jan 7 14:22:05 PST 2009.