• ### Announcements

#### Archived

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

# Tutorials on texturing using Vertex Arrays?

## Recommended Posts

I''m looking for some, but since I''m not using my computer to connect to the intarweb it''s getting hard to find something good. Does anybody has some good link to share?

nobody? wow, tnx

##### Share on other sites
vertex arrays are defined in the openGL red book available here under the Articles & Resources section.

##### Share on other sites
Its really not that hard, you just do this (I assume you already know how to use vertex arrays for vertices):

you enable the arrays

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glBindTexture(GL_TEXTURE_2D,blah)

tell openGL where the texture coords and vertices are

glVertexPointer(blah);

then you call whatever drawing method you are using

then you disable the arrays
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);

Fairly simple, shouldn't give you too much trouble.

[edited by - GreenToad on November 17, 2003 9:53:50 PM]

##### Share on other sites
Also watch your attitude in the forums, too. Sarcasm is not appreciated amongst many of the moderators & staff here. Sometimes it takes well over 7 hours for a person to respond

##### Share on other sites

I already know how to use VA, the problem is that I still don''t understand how to define the texture coordinates for the indexed vertices. Maybe it would have been better to ask that question from the beginning, but I thought it may be simple stuff that I could figure out myself with a tutorial.

##### Share on other sites
As long as you've got a texture coord for each vertex, you shouldn't have to do anything special to use them with an indexed vertex drawing call like glDrawElements().

The indices you give OpenGL when you call glDrawElements() are used for the vertices and for the texture coords, so myVertices[indexarry] uses the texture coordinate data stored at mytexcoords[indexarray].

Hope that clarifies things for you.

[edited by - GreenToad on November 17, 2003 10:05:32 PM]

##### Share on other sites
quote:
Original post by Exorcist
Also watch your attitude in the forums, too. Sarcasm is not appreciated amongst many of the moderators & staff here. Sometimes it takes well over 7 hours for a person to respond

My apologise to all the members who felt my attitude was inappropiate. My english can sound harsh sometimes. This time wasn''t intentional.

##### Share on other sites
quote:
As long as you''ve got a texture coord for each vertex, you shouldn''t have to do anything special to use them with an indexed vertex drawing call like glDrawElements(). The same indices for the vertices are used for the texture coords when you call something like glDrawElements(), so myVertices[indexarry] uses the data stored at mytexcoords[indexarray].

That makes sense. So if I pseudo-define:

vertices {-1.0,-1.0, 1.0, 1.0,-1.0, 1.0, 1.0, 1.0, 1.0,-1.0, 1.0, 1.0,-1.0,-1.0, -1.0, 1.0,-1.0, -1.0, 1.0, 1.0, -1.0,-1.0, 1.0, -1.0,}

For a cube, the texture coordinates for all 6 faces would be...

##### Share on other sites
this site seems to have some tuts on VA, I will watch them when I come back home.

[edited by - owl on November 17, 2003 10:20:22 PM]

##### Share on other sites
ahh.. the usual cube and realizing that what you might have in mind wont work. simple rule: if not ALL attributes (normal, texcoord, position) of a vertex are the same it is more than one vertex. in other words, if you want different texcoords for the corners of the sides you will not get away with just 8 vertices. the same index will be used for ALL arrays and you cant say "take vertex position 5 and texture coord 8". maybe if they someday introduce multiple index arrays (one for each attribute) you could do it.

btw. if you dont want your corners to look rounded you dont just need 3 tex coords per corner but also 3 normals, meaning you will need at least 3*8=24 vertices

##### Share on other sites
Let me see if I''m following... You mean that it isn''t possible to texturemap a cube using indexed vertex arrays? Or that I need to define the texture coordinates array with more than 8 positions?

An example would be great, but I''m still unable to find tutorials on this...

##### Share on other sites
It is kind of hard to accept that you have to duplicate vertices if a vertex has 2 texture coordinates. If you have 3dmax, try texturing a cube with Unwrap UVW. Planar map every face and export it to .3ds. Then import it back in and you will see that the vertices were split.

##### Share on other sites
heh, this makes the indexed vertex thing useless. So, my vertex array must have 24 vertices, as well as the color and texture coordinates array in order to properly texturemap the cube.

Am I right?

##### Share on other sites
ever think that at some point you''re going to have to learn how to understand the red book, instead of hoping for a tutorial on every possible combination of things you want to do?

look: every vertex in opengl can have one set of tex coords for each texture unit. That means if a vertex has more than one tex coord you need to use more than one vertex. But you don''t need to understand that now, hell you''d probably be better off NOT knowing and then asking for another tutorial when you notice it doesn''t work exactly as you expected.

GreenToad has provided you with a tutorial. Thats all there is to it. Go implement it.

##### Share on other sites
quote:
Original post by Anonymous Poster
every vertex in opengl can have one set of tex coords for each texture unit. That means if a vertex has more than one tex coord you need to use more than one vertex.

I''ll take that as a ''yes'' in relation to my last question.

For the rest, we can talk about it if you post with your real name.

Thanks.

##### Share on other sites
you might get away with a few less if you build your texture with this in mind, but it might cause a lot of headache. a vertex is not just a position. if you dont find a way to map a 3d cube to a 2d texture 8 of them arent enough. you could do it with 16 i guess, if you make it two c-like shapes or one loop and two squares, but that wont help much if you need three normals per corner for lighting.

and no, thats not making indexed vertices useless. draw your textured cube in immediate mode and you will still be sending the same number of vertices. just that a 2byte index is a lot smaller than 5 floats (20byte) or even 8(32byte). besides that a cube is always a horrible thing because of its sharp edges.

##### Share on other sites
quote:
Original post by owl
quote:
Original post by Anonymous Poster
every vertex in opengl can have one set of tex coords for each texture unit. That means if a vertex has more than one tex coord you need to use more than one vertex.

I'll take that as a 'yes' in relation to my last question.

For the rest, we can talk about it if you post with your real name.

Thanks.

Hello owl

No, index are quite useful. You just picked the worst type of model. For a box you are right, to get correct lighting you will need to define 24 verticies and an index is for the most part useless. I faced this same problem after reading the document from flexporter regarding proper lighting of a box.

Now, onto what your going to do in real life, after you finish playing with the box. Most models don't have hard edges like a box, the texture is skinned accross the model and in this case (which is most of the time) the best results come from averageing the normals at each vertex giving you a nice round surface.

Consider a plane model that has a texture streched accross the top of it, do you really want the lighthing to show off each different triangle edge. I hope not. There are edges that you do want that, and in these cases the modeler will duplicate the verticies.

If you want to go over this in detail then have a look at www.opengl.org in there future suggestions, there is a detailed description as to why this just doesn't matter. Hope that helps.

Later, Ben

[edited by - zander76 on November 18, 2003 8:38:48 AM]

##### Share on other sites
I got it now.

Thank you everyone for being kind and helpful.

• ### Forum Statistics

• Total Topics
628294
• Total Posts
2981876

• 11
• 10
• 10
• 11
• 17