Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Prozak

More Vertex Arrays Woes (will this never stop!!)

This topic is 5280 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Wow, am I tired of trying to get this working... Maybe I''m mixing stuff, I don''t know. Here are 2 pics, the 1st one shows my renderer with a typical display list, the 2nd using Vertex Arrays. Code follows. Sorry for the high compression, I just wanted to show that there seems to be something wrong with how texturing is being done, here is the rendering code:
glBindTexture(GL_TEXTURE_2D, TextureID);

glVertexPointer   ( 3, GL_DOUBLE, 0, VertexBuffer);
glTexCoordPointer ( 2, GL_DOUBLE, 0, TexBuffer);
glNormalPointer   ( GL_DOUBLE,    0, NormalBuffer);
	
size = NumFaces*3; // 3 Vertices per Face

glDrawElements(GL_TRIANGLES, size, GL_UNSIGNED_INT, FaceList);
You guys see anything wrong? Normals also seem to be failing, shadow doesnt fall on the model correctly... Jester Says: Visit Positronic Dreams!
[Hugo Ferreira][Positronic Dreams][Colibri 3D Engine][Entropy HL2 MOD]
[Yann L.][Enginuity] [Penny Arcade] [MSDN][VS RoadMap][Humus][BSPs][UGP][NeHe]
"I say we take off and nuke the entire site from orbit. It''s the only way to be sure."

Share this post


Link to post
Share on other sites
Advertisement
Not a lot of code to go on, but here are a few ideas. You are enabling all the correct arrays with glEnableClientState() and when you setup the texcoord array you are using glClientActiveTexture() to specify the texture unit the coords should be used for client side, rather than server side with glActiveTexture for actual texture binding?


glActiveTexture( GL_TEXTURE0 );
glBindTexture(GL_TEXTURE_2D, TextureID);

glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_NORMAL_ARRAY );
glEnableClientState( GL_TEXTURE_COORD_ARRAY );

glVertexPointer ( 3, GL_DOUBLE, 0, VertexBuffer);

glClientActiveTexture( GL_TEXTURE0 );
glTexCoordPointer ( 2, GL_DOUBLE, 0, TexBuffer);

glNormalPointer ( GL_DOUBLE, 0, NormalBuffer);



size = NumFaces*3; // 3 Vertices per Face


glDrawElements(GL_TRIANGLES, size, GL_UNSIGNED_INT, FaceList);

// and disable all the arrays as appropriate with glDisableClientState




[edited by - paulc on March 4, 2004 12:24:05 PM]

Share this post


Link to post
Share on other sites
the way i did it was to have a VERTEX struct and use an array of those to hold the data

struct VERTEX
{
flaot x, y, z; // The untransformed position for the vertex.

float nx,ny,nz;
DWORD color; // The vertex color.

float tu,tv;
};

glNormalPointer(GL_FLOAT,sizeof(VERTEX),&verts[0].nx);
glTexCoordPointer(2,GL_FLOAT,sizeof(VERTEX),&verts[0].tu);
glVertexPointer(3,GL_FLOAT,sizeof(VERTEX),verts);
glColorPointer(3,GL_UNSIGNED_BYTE,sizeof(VERTEX),&vert[0].color);
glDrawElements(GL_TRIANGLES,m_noTris*3,GL_UNSIGNED_INT,tris);


where tris is a DWORD array of size m_noTris*3

Share this post


Link to post
Share on other sites
Thanks guys, dumb question, in which header can I find glClientActiveTexture? And how does it work, does it limit my texture options?

Thanks for any tips on this...

Jester Says: Visit Positronic Dreams!
[Hugo Ferreira][Positronic Dreams][Colibri 3D Engine][Entropy HL2 MOD]
[Yann L.][Enginuity] [Penny Arcade] [MSDN][VS RoadMap][Humus][BSPs][UGP][NeHe]
"I say we take off and nuke the entire site from orbit. It''s the only way to be sure."

Share this post


Link to post
Share on other sites
glClientActiveTexture should be in an uptodate version of gl.h. It functions just the same as glActiveTexture, but on the client side, e.g. it does the same thing but for gl commands that are not executed immediately (I think this just applies to glTexCoordPointer calls, can''t think of anything else that uses it) - they are batched up and executed when the DrawElements or similar function is called. Okay, so it may be a bit misleading, in that the TexCoordPointer call is executed; the pointer is setup, but the data is just copied to where gl can access and use it rather than actually being drawn immediately.

Share this post


Link to post
Share on other sites
Ok, I have those 2 functions (glActiveTextureARB & glClientActiveTextureARB) in my GLCaps class that detects and assigns opengl extensions. My revised code looks like this now, but the results i get are still equal to pic 2...


glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

GLCaps.glActiveTextureARB( GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, TextureID);

glTexCoordPointer ( 2, GL_DOUBLE, 0, TexBuffer);
glVertexPointer ( 3, GL_DOUBLE, 0, VertexBuffer);
GLCaps.glClientActiveTextureARB( GL_TEXTURE0 );

size = NumFaces*3; // 3 vertices per Face

glDrawElements(GL_TRIANGLES, size, GL_UNSIGNED_INT, FaceList);

glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);


Jester Says: Visit Positronic Dreams!
[Hugo Ferreira][Positronic Dreams][Colibri 3D Engine][Entropy HL2 MOD]
[Yann L.][Enginuity] [Penny Arcade] [MSDN][VS RoadMap][Humus][BSPs][UGP][NeHe]
"I say we take off and nuke the entire site from orbit. It''s the only way to be sure."

Share this post


Link to post
Share on other sites
Another question,
When we define normals and texture coords, we define them allways by vertex, never by face, right?

I don''t think we can define texture coordinates UV for a face, but we can define the normals of a face with XYZ, or per vertex...

So our normals, texture coordinates are allways defined by vertex, right?

Jester Says: Visit Positronic Dreams!
[Hugo Ferreira][Positronic Dreams][Colibri 3D Engine][Entropy HL2 MOD]
[Yann L.][Enginuity] [Penny Arcade] [MSDN][VS RoadMap][Humus][BSPs][UGP][NeHe]
"I say we take off and nuke the entire site from orbit. It''s the only way to be sure."

Share this post


Link to post
Share on other sites
The ClientActiveTexture call should go just before the TexCoordPointer call, its performing the same operation as ActiveTexture before a BindTexture call.

Share this post


Link to post
Share on other sites
quote:
Original post by pentium3id
Another question,
When we define normals and texture coords, we define them allways by vertex, never by face, right?

I don''t think we can define texture coordinates UV for a face, but we can define the normals of a face with XYZ, or per vertex...

So our normals, texture coordinates are allways defined by vertex, right?



By convention, all data is stored in the vertices and the face description then becomes a list of vertices in that face.
So yes, all normals and texture coords should be stored in the verts. As you correctly pointed out, there is no logical representation to map textures to a face.


Share this post


Link to post
Share on other sites
Thanks paulc, still unsuccessful, current code:


GLCaps.glActiveTextureARB( GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, TextureID);

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glVertexPointer ( 3, GL_DOUBLE, 0, VertexBuffer);
GLCaps.glClientActiveTextureARB( GL_TEXTURE0 );

glTexCoordPointer ( 2, GL_DOUBLE, 0, TexBuffer);
size= FaceNum*3;

glDrawElements(GL_TRIANGLES, size, GL_UNSIGNED_INT, FaceList);

glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);


...Also, do I really have to do glEnableClientState, or can I do it once, at program initialization? Cause I''m currently doing it once per frame...

psamty10, thanks for clearing that up.

Jester Says: Visit Positronic Dreams!
[Hugo Ferreira][Positronic Dreams][Colibri 3D Engine][Entropy HL2 MOD]
[Yann L.][Enginuity] [Penny Arcade] [MSDN][VS RoadMap][Humus][BSPs][UGP][NeHe]
"I say we take off and nuke the entire site from orbit. It''s the only way to be sure."

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!