Vertex Arrays
I am starting to use vertex arrays instead of display lists. Problem is my rendering is all FUBAR! If I use GL_POINTS my rendering looks ok. Once I move to polygons all goes to hell? Now my thoughts are I need to align the vertex data as a GL_TRIANGLE_STRIP needs it in the array before I send it? Am I wrong? That goes I suppose for any polygon. If so how are people doing their vertex data sort/assign algorithm? Thanks
You did not say whether you were using glDrawArrays() or glDrawElements(). The first is useful for drawing the points, since there is no need to produce polygons. You would have to use a different array with many duplicate entries to draw polygons with glDrawArrays(). glDrawElements() accepts a second array of indices into the array of vertices (and normals and colours, if you use them).
So please be a bit more specific!
So please be a bit more specific!
I have all my vertex x,y,z data stored in a 2D array struct.
[code]
struct Vertex
{
float x;
float y;
float z;
};
Vertex terrain[256][256] = {0};
[code]
I am using glDrawArrays(). I don't see how glDrawElements() is going to work when I want float values and not integer values? Thanks
[code]
struct Vertex
{
float x;
float y;
float z;
};
Vertex terrain[256][256] = {0};
[code]
I am using glDrawArrays(). I don't see how glDrawElements() is going to work when I want float values and not integer values? Thanks
I am asking why my terrain mesh looks like long white blocks of lines? Is it because I don't have the vertex data arranged so
terrain[0][0].x terrain[0][0].y terrain[0][0].z = point 0
on the strip vertex and
terrain[0][1].x terrain[0][1].y terrain[0][1].z = point 1
terrain[0][2].x terrain[0][2].y terrain[0][1].z = point 2
terrain[0][3].x terrain[0][3].y terrain[0][3].z = point 3
terrain[0][4].x terrain[0][4].y terrain[0][4].z = point 0 on next triangle???
and so forth??
Because right now my 2D array isn't setup to have one right after another strip data or even quads data. terrain[0][0] through terrain[0][255] is x being incremented from 0-255 and y being whatever my heightmap is and z is 0 all the way until I move to terrain[1][0] now z is 1. Now thats why I am asking does this data need to be aligned/arranged so it corresponds with GL_TRIANGLE_STRIP data
vertecies
0,1
2,3
and not
random numbers because I have my 2D array setup so I can use it with glVertex3f() calls?? where I can increment my elements to get the numbers I need? If this is the problem how in the world am I suppose to align the data so it works correctly? I am new to glVertexArrays!
terrain[0][0].x terrain[0][0].y terrain[0][0].z = point 0
on the strip vertex and
terrain[0][1].x terrain[0][1].y terrain[0][1].z = point 1
terrain[0][2].x terrain[0][2].y terrain[0][1].z = point 2
terrain[0][3].x terrain[0][3].y terrain[0][3].z = point 3
terrain[0][4].x terrain[0][4].y terrain[0][4].z = point 0 on next triangle???
and so forth??
Because right now my 2D array isn't setup to have one right after another strip data or even quads data. terrain[0][0] through terrain[0][255] is x being incremented from 0-255 and y being whatever my heightmap is and z is 0 all the way until I move to terrain[1][0] now z is 1. Now thats why I am asking does this data need to be aligned/arranged so it corresponds with GL_TRIANGLE_STRIP data
vertecies
0,1
2,3
and not
random numbers because I have my 2D array setup so I can use it with glVertex3f() calls?? where I can increment my elements to get the numbers I need? If this is the problem how in the world am I suppose to align the data so it works correctly? I am new to glVertexArrays!
First you enable the array(s) (glEnableClientState(GL_VERTEX_ARRAY) etc) and submit the pointers (glVertexPointer(), glColorPointer() etc.) -- these are floats. I assume you got that far. But your array of vertices is just a non-repeating list -- a set. You need to tell OpenGL which vertices define which triangles. You do that with glDrawElements and a block of index data. The indices are integers, but the vertex data is still the same floats.
GL then dereferences the index array, jumping around inside the vertex (and color and other arrays) according to the indices. It trades off repeated vertex data for index data. So the verts will be a big list as you have them, but the index array will look like:
0, 256, 1, 257, 2, 258, ...
256, 512, 257, 513, 258, ...
if you use GL_TRIANGLE_STRIP. Please don't make me write code tonight, I'm too tired... Is there something that I don't realize is not obvious?
GL then dereferences the index array, jumping around inside the vertex (and color and other arrays) according to the indices. It trades off repeated vertex data for index data. So the verts will be a big list as you have them, but the index array will look like:
0, 256, 1, 257, 2, 258, ...
256, 512, 257, 513, 258, ...
if you use GL_TRIANGLE_STRIP. Please don't make me write code tonight, I'm too tired... Is there something that I don't realize is not obvious?
Now I am really confused? :sorry: What is the deal with glDrawElements() and a second array? Here is what I got. One 2D array of all my vertex coordinates x,y,z. for a 256x256 map. I am totally lost if you are referring to a second array called indices? Isnt' that what my vertex points are?
Why is it so hard to just say that indices array is an array that holds the element# corresponding to the vertex array's elements in which you want your polygons vertexs drawn?
if terrain is a 32x32 2D array
so terrain[0][0].x and terrain[0][0].y and terrain[0][0].z would be called first and then
terrain[1][0].x and terrain[1][0].y and terrain[1][0].z would be called second
if I am using a 2D array.
This makes sense now after beating my face into brick wall.
Now my problem is with texturing using glClientActiveTexutreARB(GL_TEXTURE0_ARB) and glClientActiveTexutreARB(GL_TEXTURE1_ARB) with arrays. What is the correct setup of them? When do I use glBindTexture or setup the texture filtering with arrays? Thanks
Code:
unsigned int indices[4] = {0, 32, 1, 33};if terrain is a 32x32 2D array
so terrain[0][0].x and terrain[0][0].y and terrain[0][0].z would be called first and then
terrain[1][0].x and terrain[1][0].y and terrain[1][0].z would be called second
if I am using a 2D array.
This makes sense now after beating my face into brick wall.
Now my problem is with texturing using glClientActiveTexutreARB(GL_TEXTURE0_ARB) and glClientActiveTexutreARB(GL_TEXTURE1_ARB) with arrays. What is the correct setup of them? When do I use glBindTexture or setup the texture filtering with arrays? Thanks
I am now having an issue with texturing. I have a single texture 1/2 red and 1/2 black. When the terrain is rendering I get this red,black texture and then it goes black,red and red, black and black,red??? Here is my code to initialize my texture array
Is that correct for GL_TRIANGLES_STRIP???
Code:
for(z = 0; z < MAP_Z; z++)
{
for(x = 0; x < MAP_X; x++)
{
tex_coord[z][x].x = float(x % 2);
tex_coord[z][x].y = float(z % 2);
}
}Is that correct for GL_TRIANGLES_STRIP???
Quote:Originally posted by Mars_999
Why is it so hard to just say that indices array is an array that holds the element# corresponding to the vertex array's elements in which you want your polygons vertexs drawn?
Sorry but that's what an index is! I don't understand why I would have to provide a dictionary definition.
Texture coordinates have to range from [0,1]. If you use numbers greater than one, the texture wraps, using truncation (modulo 1). You probably have to divide by the size of the texture.
So I think, instead of float(x % 2), you should be using x/MAP_X and instead of float( z % 2), z/MAP_Z. But I am assuming that MAP_X and MAP_Z are the dimensions of your texture map. I am also assuming that you want the texture to extend across the entire terrain.
Apologize for late reply -- Blackout and all that.
So I think, instead of float(x % 2), you should be using x/MAP_X and instead of float( z % 2), z/MAP_Z. But I am assuming that MAP_X and MAP_Z are the dimensions of your texture map. I am also assuming that you want the texture to extend across the entire terrain.
Apologize for late reply -- Blackout and all that.
Quote:Originally posted by Feanor
Texture coordinates have to range from [0,1]. If you use numbers greater than one, the texture wraps, using truncation (modulo 1). You probably have to divide by the size of the texture.
So I think, instead of float(x % 2), you should be using x/MAP_X and instead of float( z % 2), z/MAP_Z. But I am assuming that MAP_X and MAP_Z are the dimensions of your texture map. I am also assuming that you want the texture to extend across the entire terrain.
Apologize for late reply -- Blackout and all that.
Well I got it to work but I had to do this
Code:
for(z = 0; z < MAP_Z; z++)
{
for(x = 0; x < MAP_X; x++)
{
tex_coord[z][x].x = float(x);
tex_coord[z][x].y = float(z);
}
}Now using x/MAP_X wouldn't that take one whole texture and wrap it over the entire terrain? If so that would look ugly as sin due to the terrain is 256x256 and a texture of 1024x1024 would still look ugly? Thanks for the reply though. Yeah blackouts would and do suck A**! I MUST HAVE EM radiation daily from my computer!!
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| ? Export Vertex Arrays from Gfx App ? | Elphaba | 2 | 2,492 |
Jun 11, 2009 12:39 PM Last Post: Elphaba |
|
| VBOs and Vertex Arrays in OpenGL not working | Talyn | 6 | 5,212 |
Jul 8, 2008 01:14 PM Last Post: Fenris |
|
| Display Lists or Vertex Arrays with texturing | seven | 6 | 3,316 |
Oct 17, 2005 09:24 AM Last Post: seven |
|
| How do you set up your vertex arrays? | Nevada | 3 | 3,046 |
Aug 5, 2004 07:53 AM Last Post: Jake |
|
| Probelms with multitexture vertex arrays | Bossa Nova | 2 | 2,547 |
Jun 24, 2003 04:06 PM Last Post: Bossa Nova |
|

