Archived

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

Vertex Arrays...

This topic is 5153 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

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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites