Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualic0de

Posted 07 December 2012 - 05:31 PM

Do you want to load just a basic mesh and display it or do you want to do something cool and construct it from a heightmap or something? How are you using opengl in java is it JOGL or lwjgl or something else? If your using the heightmap way what you want to do is load a grayscale image in a way that you can address each pixel and ill give you some psuedocode:

int vertindex;
for(int x = 0; x < image.w; x++)
{
	 for(int y = 0; y < image.h; y++)
	 {
		  vertices[vertindex*3] = x; //vertex x-coordinate
		  vertices[1 + vertindex*3] = y; //vertex y-coordinate
		  vertices[2 + vertindex*3] = image.pixels[x][y]; //vertex z-coordinate
		  vertindex += 1;
	 }
}
glEnableClientState(GL_VERTEX_ARRAY);
unsigned int vBuffer;
glGenBuffers(1, &vBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vBuffer);
glBufferData(GL_ARRAY_BUFFER, vertindex  * 3 * sizeof(float), vertices, GL_STATIC_DRAW);
glVertexPointer(3, GL_FLOAT, 0, 0);
glDrawArrays(GL_LINES, 0, vertindex);

That's basically how you do it in psuedomodern opengl.

Legacy opengl is a bit easier but is reeeeaaaaly slow:

int vertindex;
glBegin(GL_LINES);

for(int x = 0; x < image.w; x++)
{
	 for(int y = 0; y < image.h; y++)
	 {
		  glVertex3f(x, y, image.pixels[x][y]);  
	 }
}
glEnd();

attached is a sample heightmap

#7ic0de

Posted 07 December 2012 - 05:29 PM

Do you want to load just a basic mesh and display it or do you want to do something cool and construct it from a heightmap or something? How are you using opengl in java is it JOGL or lwjgl or something else? If your using the heightmap way what you want to do is load a grayscale image in a way that you can address each pixel and ill give you some psuedocode:

int vertindex;
for(int x = 0; x < image.w; x++)
{
	 for(int y = 0; y < image.h; y++)
	 {
		  vertices[vertindex*3] = x; //vertex x-coordinate
		  vertices[1 + vertindex*3] = y; //vertex y-coordinate
		  vertices[2 + vertindex*3] = image.pixels[x][y]; //vertex z-coordinate
		  vertindex += 1;
	 }
}
glEnableClientState(GL_VERTEX_ARRAY);
unsigned int vBuffer;
glGenBuffers(1, &vBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vBuffer);
glBufferData(GL_ARRAY_BUFFER, vertindex  * 3 * sizeof(float), vertices, GL_STATIC_DRAW);
glVertexPointer(3, GL_FLOAT, 0, 0);
glDrawArrays(GL_LINES, 0, vertindex);

That's basically how you do it in psuedomodern opengl.

Legacy opengl is a bit easier but is reeeeaaaaly slow:

int vertindex;
for(int x = 0; x < image.w; x++)
{
	 for(int y = 0; y < image.h; y++)
	 {
		  glVertex3f(x, y, image.pixels[x][y]);  
	 }
}

attached is a sample heightmap

#6ic0de

Posted 07 December 2012 - 05:24 PM

Do you want to load just a basic mesh and display it or do you want to do something cool and construct it from a heightmap or something? How are you using opengl in java is it JOGL or lwjgl or something else? If your using the heightmap way what you want to do is load a grayscale image in a way that you can address each pixel and ill give you some psuedocode:

int vertindex;
for(int x = 0; x < image.w; x++)
{
	 for(int y = 0; y < image.h; y++)
	 {
		  vertices[vertindex*3] = x; //vertex x-coordinate
		  vertices[1 + vertindex*3] = y; //vertex y-coordinate
		  vertices[2 + vertindex*3] = image.pixels[x][y]; //vertex z-coordinate
		  vertindex += 1;
	 }
}
glEnableClientState(GL_VERTEX_ARRAY);
unsigned int vBuffer;
glGenBuffers(1, &vBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vBuffer);
glBufferData(GL_ARRAY_BUFFER, vertindex  * 3 * sizeof(float), vertices, GL_STATIC_DRAW);
glVertexPointer(3, GL_FLOAT, 0, 0);
glDrawArrays(GL_LINES, 0, vertindex);

That's basically how you do it in psuedomodern opengl.

Legacy opengl is a bit easier but is reeeeaaaaly slow:

int vertindex;
for(int x = 0; x < image.w; x++)
{
	 for(int y = 0; y < image.h; y++)
	 {
		  glVertex3f(x, y, image.pixels[x][y]);  
	 }
}

#5ic0de

Posted 07 December 2012 - 05:24 PM

Do you want to load just a basic mesh and display it or do you want to do something cool and construct it from a heightmap or something? How are you using opengl in java is it JOGL or lwjgl or something else? If your using the heightmap way what you want to do is load a grayscale image in a way that you can address each pixel and ill give you some psuedocode:

int vertindex;
for(int x = 0; x < image.w; x++)
{
	 for(int y = 0; y < image.h; y++)
	 {
		  vertices[vertindex*3] = x; //vertex x-coordinate
		  vertices[1 + vertindex*3] = y; //vertex y-coordinate
		  vertices[2 + vertindex*3] = image.pixels[x][y]; //vertex z-coordinate
		  vertindex += 1;
	 }
}
glEnableClientState(GL_VERTEX_ARRAY);
unsigned int vBuffer;
glGenBuffers(1, &vBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vBuffer);
glBufferData(GL_ARRAY_BUFFER, vertindex  * 3 * sizeof(float), vertices, GL_STATIC_DRAW);
glVertexPointer(3, GL_FLOAT, 0, 0);
glDrawArrays(GL_LINES, 0, vertindex);

That's basically how you do it in psuedomodern opengl.

Legacy opengl is a bit easier but is reeeeaaaaly slow:

int vertindex;
for(int x = 0; x < image.w; x++)
{
	 for(int y = 0; y < image.h; y++)
	 {
          glVertex3f(x, y, image.pixels[x][y]) ;   
	 }
}

#4ic0de

Posted 07 December 2012 - 05:18 PM

Do you want to load just a basic mesh and display it or do you want to do something cool and construct it from a heightmap or something? How are you using opengl in java is it JOGL or lwjgl or something else? If your using the heightmap way what you want to do is load a grayscale image in a way that you can address each pixel and ill give you some psuedocode:

int vertindex;
for(int x = 0; x < image.w; x++)
{
	 for(int y = 0; y < image.h; y++)
	 {
		  vertices[vertindex*3] = x; //vertex x-coordinate
		  vertices[1 + vertindex*3] = y; //vertex y-coordinate
		  vertices[2 + vertindex*3] = image.pixels[x][y]; //vertex z-coordinate
		  vertindex += 1;
	 }
}
glEnableClientState(GL_VERTEX_ARRAY);
unsigned int vBuffer;
glGenBuffers(1, &vBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vBuffer);
glBufferData(GL_ARRAY_BUFFER, vertindex  * 3 * sizeof(float), vertices, GL_STATIC_DRAW);
glVertexPointer(3, GL_FLOAT, 0, 0);
glDrawArrays(GL_LINES, 0, vertindex);

That's basically how you do it in psuedomodern opengl.

#3ic0de

Posted 07 December 2012 - 05:17 PM

Do you want to load just a basic mesh and display it or do you want to do something cool and construct it from a heightmap or something? How are you using opengl in java is it JOGL or lwjgl or something else? If your using the heightmap way what you want to do is load a grayscale image in a way that you can address each pixel and ill give you some psuedocode:

int vertindex;
for(int x = 0; x < image.w; x++)
{
	 for(int y = 0; y < image.h; y++)
	 {
		  vertices[vertindex*3] = x;
		  vertices[1 + vertindex*3] = y;
		  vertices[2 + vertindex*3] = image.pixels[x][y];
		  vertindex += 1;
	 }
}
glEnableClientState(GL_VERTEX_ARRAY);
unsigned int vBuffer;
glGenBuffers(1, &vBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vBuffer);
glBufferData(GL_ARRAY_BUFFER, vertindex  * 3 * sizeof(float), vertices, GL_STATIC_DRAW);
glVertexPointer(3, GL_FLOAT, 0, 0);
glDrawArrays(GL_LINES, 0, vertindex);

That's basically how you do it in psuedomodern opengl.

PARTNERS