View Full Version : grid mesh

06-23-2010, 03:32 AM
Hi all.
I have a 2 dimention array of vertexes with dynamic size. All the vertexes has a given color. I want to draw these as a grid and i want the colors to be interpolated throughout the whole grid.
today I draw them like this:

//this is a simple version of my drawing. I also calculate normals and set material for the lights
for (int x = 0; x < points.length; x++) {
for (int y = 0; y < points[x].length; y++) {
if (x == points.length - 1 || y == points[x].length - 1) {
} else {
gl.glColor4f(points[x][y].getWeightColor()[0], points[x][y].getWeightColor()[1], points[x][y].getWeightColor()[2], 1.0f);
gl.glVertex3d(points[x][y].getX(), points[x][y].getY(), points[x][y].getDrawnZ());
gl.glVertex3d(points[x][y + 1].getX(), points[x][y + 1].getY(), points[x][y + 1].getDrawnZ());
gl.glVertex3d(points[x + 1][y + 1].getX(), points[x + 1][y + 1].getY(), points[x + 1][y + 1].getDrawnZ());
gl.glVertex3d(points[x + 1][y].getX(), points[x + 1][y].getY(), points[x + 1][y].getDrawnZ());

but this will create lots of individual polygons/quads. The color will be interpolated within each quad, but I want the grid to interpolate betwen quads as well. If you know what i mean.
Is there a better way of doing this? with quadstrip/polygon or something else?

GL Starter
06-23-2010, 04:28 AM
Give color to each vertex, then these colors will be interpolated.

Try the below code. It will create a Quad with four colors interpolated.


glColor4f(1,0,0,1); // Red left bottom corner
glVertex3d(0, 0, 0);
glColor4f(0,1,0,1); // Green left top corner
glVertex3d(0, 1, 0);
glColor4f(0,0,1,1); // Blue right top corner
glVertex3d(1, 1, 0);
glColor4f(1,1,1,1); // white right bottom corner
glVertex3d(1, 0, 0);

06-23-2010, 05:35 AM
Thanks for the reply.. This made it nicer to look at...
Do you know if theres a way to take the vertexes and make one big polygon out of it?

GL Starter
06-24-2010, 05:08 AM
Do you know if theres a way to take the vertexes and make one big polygon out of it?

Not clear. what do u mean by big polygon ?

06-24-2010, 03:24 PM

07-22-2010, 06:59 AM
one big polygon... chose my words poorly there... I ment one big mesh.