Vertex Arrays...

Started by
8 comments, last by fireking 20 years, 5 months ago
im trying to get my terrain engine to support vertex arrays now, and im having a lot of trouble... i read the red book, i think chapter 2, and im implementing from the knowledge they teach in that chapter here's my generic crappy function, i dont know if its correct, as currently i have an array problem that prevents me from compiling... //the make your cool array function

void MakeTerrainVertexArray(BYTE *pHeightMap,float *vertsave,float *texcoordsave)
{
	glEnableClientState(GL_VERTEX_ARRAY);
	int vertsize=3*((MAP_SIZE*MAP_SIZE)/STEP_SIZE);
	int texcoordsize=2*((MAP_SIZE*MAP_SIZE)/STEP_SIZE);
	int vcount=0;
	int tcount=0;
	float *verts=new float[vertsize];
	float *texcoords= new float[texcoordsize];
	for(int iz=0;iz < MAP_SIZE-STEP_SIZE;iz+=STEP_SIZE)
	{
		for(int ix=0;ix < MAP_SIZE-1;ix+=STEP_SIZE)
		{

			texcoords[tcount]=ix/((float)MAP_SIZE-(float)STEP_SIZE);
			texcoords[tcount+1]=1-(iz/((float)MAP_SIZE-(float)STEP_SIZE));
			tcount+=2;

			verts[vcount]=ix;
			verts[vcount+1]=Height(pHeightMap,ix,iz)*HEIGHT_RATIO;
			verts[vcount+2]=iz;
			vcount+=3;

			texcoords[tcount]=ix/((float)MAP_SIZE-(float)STEP_SIZE);
			texcoords[tcount+1]=1-(iz/((float)MAP_SIZE-(float)STEP_SIZE));
			tcount+=2;

			verts[vcount]=ix;
			verts[vcount+1]=Height(pHeightMap,ix,iz+STEP_SIZE)*HEIGHT_RATIO;
			verts[vcount+2]=iz+STEP_SIZE;
			vcount+=3;
		}
	}
	glVertexPointer(3,GL_FLOAT,0,verts);
	vertsave=verts;
	texcoordsave=texcoords;
}
  
and i dont have a drawing function yet, cuz im not clear on how to actually draw the array... also, im not storing the tex coords, because im not sure on how to use tex coords in mult-texturing with texturecoord arrays... i use this to set my texture coordinates in my regular drawing routine...

void SetTextureCoord(float x, float z)
{
	float u =  x / ((float)MAP_SIZE-(float)STEP_SIZE);
	float v =  z / ((float)MAP_SIZE-(float)STEP_SIZE);
	glMultiTexCoord2fARB(GL_TEXTURE0_ARB, u,1- v);
	glMultiTexCoord2fARB(GL_TEXTURE1_ARB, u,1- v);
}
  
the way the book describes these vertex array functions to me, tells me that its gonna use glTexCoord2f() when i use one of the glArrayElement/glDrawElements functions... which isnt what i want since im using multitexturing... if someone could help me, id greatly appreciate it, this stuff is confusing [edited by - fireking on November 9, 2003 4:39:12 AM]
--FirekingOwner/LeaderFiregames Development &Blackdragon Studios
Advertisement
actually ive got that part working now, i just need to know how to draw it and i need to know someone''s comments on multi-texturing with texture coord arrays
--FirekingOwner/LeaderFiregames Development &Blackdragon Studios
for multi-texturing with texture coordinate arrays you have to setup the texture array pointer for each active texture unit as you would in single texturing.

* activate texture unit
* set texture for that unit
* set texture coordinate pointer
* set any modes you want on it
* activate next texture unit
* set texture for that unit
* set texture coordinate pointer
* set any modes you want on it
etc etc
Or forget about the texture array!

You can also project a texture onto your scape mesh.
Using glTexGen() you can easily project a texture on top of it.
If you dont change the texture matrix, the uvw is the same as the vertex xyz!
You probably will need to scale this texture to fit perfectly onto your scape.

pseudo:
glMatrixMode(GL_TEXTURE)glLoadIdentity()glScale(width, height, 1)glMatrixMode(GL_MODELVIEW)... render!! beware.. now all textures are scaled!So we want to set this to normal again...glMatrixMode(GL_TEXTURE)glLoadIdentity()glMatrixMode(GL_MODELVIEW)
i still dont know how to draw it....

grrrr
--FirekingOwner/LeaderFiregames Development &Blackdragon Studios
glVertexPointer(3, GL_FLOAT, 0, your_vertex_array);
glTexCoordPointer(2, GL_FLOAT, 0, your_texcoord_array);
glDrawArrays(GL_TRIANGLES, 0, number_of_vets);

Easy

My Website | Everything you need to know about 3D Graphics | Google | Search the Forums
ok that works, but there are two problems:

1. for every strip that goes across on the terrain, there is another strip rendered upside down, only visible when you go under the terrain and look up (because i have cull faces on)

2. multitexturing doesnt work on that
--FirekingOwner/LeaderFiregames Development &Blackdragon Studios
1) reverse triangle indices in generation code for evry other row.

2) use glClientActiveTexture(...)
You should never let your fears become the boundaries of your dreams.
where is the documentation for glClientActiveTexture, its not in the blue book
--FirekingOwner/LeaderFiregames Development &Blackdragon Studios
look up the GL_ARB_multitexture extension (google is a good start) and that will tell you about it

This topic is closed to new replies.

Advertisement