Skip to main content
gamedev.net
🔒 Locked

texturing a cube

Started by Endar Oct 13, 2005 at 12:41 AM 6 replies 650+ views
Original Post
Endar
Endar
I have a simple cube model, and a simple bitmap texture. I'm having problems with the texture coords. I'm using OpenGL vertex arrays so I have 8 vertices, and a list of indices. How do I set the texture coords so that I get the texture on all sides?
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
timw
timw
it's the same thing as texture mapping a quad, or two triangles.

ie upper left point (0,0)
upper right (1,0)
bottom left (0,1)
bottom right (1,1)

assuming (0,0) is the upper left corner of your bitmap

do this for every side. is this what your asking?
Endar
Endar
Well, here's what I have:

/** * A class to represent a vertex and its texture coordinates. */class CVertex3d{public:	util::CVector3d point;	///< The position of this vertex in 3d space	util::CVector3d normal;	///< The normal vector of the vertex.	float u,				///< Component of the texture coordinates		  v;				///< Component of the texture coordinates	video::CColor color;	///< Color for the vertexpublic:	// misc member functions};


And I have 8 of these that represent a cube. Should this be changed?
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
Brother Bob
Brother Bob
A cube have 8 corners, but each corner actually have 3 different sets of texture coordinates and normals, so the cube, when using texture coordinates and/or normals, actually have 24 vertices, not 8.

For vertex arrays, a cube or other objects that consists of "hard" edged only, is actually the worst case concerning vertex sharing.
Endar
Endar
So, even though I'm using vertex arrays, I need to have 24 vertices, one copy for each set of texture coords.

So, this pretty much means that whenever I have two polygons with one point in common, I'll need two versions of that vertex?

Remind me again, the advantages of vertex arrays?
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
dave
dave
Well in vertex arrays are good in most cases where you can remove redundant vertices. Here the cube with a possibly different texture on each face is a worst case scenario. But supposing for a minute that you have a panel mesh. This is made up of a grid of quads. There will be lots of shared vertices. Supposing that you where applying a single texture right accross the entire face of the mesh then the vertices in middle are shared between multiple quads, but are identical. These can be removed. You would then update the indexes so that they point to the first occurance of the vertex in the vertex array.

I hope that makes it clear.

ace
Kalidor
Kalidor
Quote:
Original post by Endar
Remind me again, the advantages of vertex arrays?
In addition to what upside-down-face boy said...

One draw call instead of (numVertices + numColors + numNormals + numTexCoords*numTexUnits) draw calls.
dave
dave
Original post by Kalidor
Quote:
Original post by Endar
Remind me again, the advantages of vertex arrays?
In addition to what upside-down-face boy said...
quote]

I think you're the first person to call me that on these boards, hehe

ace

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.