Jump to content
  • Advertisement
Sign in to follow this  
_WeirdCat_

draw elements and range and strange draw and wrong index es 2.0

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

First of all ogl es 2.0 accepts only indices that are unsigned short, but it works the same for unsigned int as indice type... i have no idea why, but using unsigned short or unsigned int doesn't throw any gl errors.

 

first i want you to see pics:

 

this is what i am getting:

device-2015-12-14-022400.png

 

 

 

as you can see theres a space between 4 meshes (i need them to be 'connected')

 

 

so i tried to translate each of meshes drawn by -1, and i got this:

device-2015-12-14-022233.png

 

this tells me that i think that last set of indices are not draw since its fft ocean it should be tileable ?

const int OCEAN_GRID_SIZE 	= 1200;
const int SIM_GRID_SIZE 	= 64;
const int SIM_ARR_LEN		= SIM_GRID_SIZE * SIM_GRID_SIZE;

unsigned short indices		[ SIM_ARR_LEN * 2];

//generate indices
   int i; int j;
   int cnt = -1;
   for (j=0; j < SIM_GRID_SIZE-1; j++) //z
	   for (i=0; i < SIM_GRID_SIZE; i++) //x
	   {
		   cnt = cnt + 1;
		   indices[cnt] = (unsigned short)ArrI(i,j+1);
		   cnt = cnt + 1;
		   indices[cnt] = (unsigned short)ArrI(i,j);

	   }


    glGenBuffers(1, &elementbuffer);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementbuffer);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, 2 * SIM_ARR_LEN * sizeof(unsigned short), indices, GL_STATIC_DRAW);
                                                 
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

+ and image of how i set vertices: since i draw them by horizontal strips (using tri strips) i do it like that

ind.png

 

 

 

this is how i position a mesh (which is translated when drawn)

for (int y=0; y < SIM_GRID_SIZE; y++)
for (int x=0; x < SIM_GRID_SIZE; x++)
{
i = ArrI(x,y);
float ax = float(OCEAN_GRID_SIZE)*(float(x)/float(SIM_GRID_SIZE));
float az = float(OCEAN_GRID_SIZE)*(float(y)/float(SIM_GRID_SIZE));

AOS[i].v = vec3(ax, heightmap[i] / WORLD_SCALE, az);
}



int ArrI(int x, int y)
{
return y*SIM_GRID_SIZE + x;
}

code above shows that OCEAN_GRID_SIZE is 1200.0 so when x or y reaches 64 (it never does and if i change float(SIM_GRID_SIZE) to 63.0

i get exactly the same result as in second picture. So maybe i have something wrong with fft and thats why it does not cover? or maybe this is floating point issue, but it seems not since texture generated on the mesh has no seams (since)

AOS[ArrI(i,j)].t 	= vec2(float(i*32)/64.0, float(j*32)/64.0); //scaled texture coords so i actually see some seamless tiles

and like in second picture, vertices and texcoords do not cover.

 

 

 

finally draw code:


    float DirX[9] = {0.0, -1.0, 1.0,  0.0, 0.0, -1.0, 1.0, -1.0,  1.0};
    float DirY[9] = {0.0,  0.0, 0.0, -1.0, 1.0,  1.0, 1.0, -1.0, -1.0};

for (i=0; i < 9; i++) //draw 9 meshes
{
	mat4 trans;
	trans.LoadIdentity();
	trans.Translate(DirX[i]*float(OCEAN_GRID_SIZE), 0.0,  DirY[i]*float(OCEAN_GRID_SIZE));

	water_shader->SendWorldMatrixtoShader(trans);
	water_shader->SendMVPtoShader((trans * ACTUAL_VIEW) * ACTUAL_PROJECTION);
	for (int j=0; j < SIM_GRID_SIZE; j++)
	{

		 glDrawElements(GL_TRIANGLE_STRIP, GLsizei(SIM_GRID_SIZE*2), GL_UNSIGNED_SHORT,
				 (void*)( j*SIM_GRID_SIZE*2*sizeof(unsigned short)) );
	}



}

SO is this a flaotingpoint precision issue? or maybe i don't draw last stripe? or maybe something else?

Edited by WiredCat

Share this post


Link to post
Share on other sites
Advertisement

I don't know what your issue is but when you are casting here:

indices[cnt] = (unsigned short)ArrI(i,j+1);

Are you getting any values that are too big?

 

try this:

static const unsigned int MAX_VERTEX = (unsigned int)(unsigned short)(-1);
if(ArrI(i,j+1) > MAX_VERTEX)
  // Too big

Share this post


Link to post
Share on other sites

this is why the loop stops at SIM_GRID_SIZE - 2

 

   for (j=0; j < SIM_GRID_SIZE-1; j++)
  for (i=0; i < SIM_GRID_SIZE; i++)
  {
  cnt = cnt + 1;
  indices[cnt] = (unsigned short)ArrI(i,j+1);
  cnt = cnt + 1;
  indices[cnt] = (unsigned short)ArrI(i,j);
 
  }
 
 
it looks like i should draw additional vertices on that border, but then i won't get any data from heightfield for those 
 
anyway i think this may have something with that. but somehow i dont see it

Share this post


Link to post
Share on other sites

The problem maybe because of the fact that in the code:

for (int y=0; y < SIM_GRID_SIZE; y++)
for (int x=0; x < SIM_GRID_SIZE; x++)
{
i = ArrI(x,y);
float ax = float(OCEAN_GRID_SIZE)*(float(x)/float(SIM_GRID_SIZE));
float az = float(OCEAN_GRID_SIZE)*(float(y)/float(SIM_GRID_SIZE));

AOS[i].v = vec3(ax, heightmap[i] / WORLD_SCALE, az);
}

Your ax and az never will be equal to the OCEAN_GRID_SIZE since both x and y are less than SIM_GRID_SIZE, I guess you have to generate one more row and column of vertices by setting your for to be:

for (int y=0; y <= SIM_GRID_SIZE; y++)
for (int x=0; x <= SIM_GRID_SIZE; x++)
{
i = ArrI(x,y);
float ax = float(OCEAN_GRID_SIZE)*(float(x)/float(SIM_GRID_SIZE));
float az = float(OCEAN_GRID_SIZE)*(float(y)/float(SIM_GRID_SIZE));

AOS[i].v = vec3(ax, heightmap[i] / WORLD_SCALE, az);
}

This will change the number of vertices and meshes and every thing else so you need to reconsider the size of stuff

 

or easier change will be the below since you need your ocean grid count to be the same as the height map:

for (int y=0; y < SIM_GRID_SIZE; y++)
for (int x=0; x < SIM_GRID_SIZE; x++)
{
i = ArrI(x,y);
float ax = float(OCEAN_GRID_SIZE)*(float(x)/float(SIM_GRID_SIZE-1));
float az = float(OCEAN_GRID_SIZE)*(float(y)/float(SIM_GRID_SIZE-1));

AOS[i].v = vec3(ax, heightmap[i] / WORLD_SCALE, az);
}

I guess that's a way better solution, ignore the first one biggrin.png

Edited by IYP

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!