newb - how to colorize selected vertexes

Hi

Its my first day using jogl, so im not sure if im using the api in the suggested way.

I drawn a surface containing ~35.000 squares.

My strategy:


 // incomplete pseudocode
glBegin(GL.GL_QUADS)
for ( x = 0 ... 200 ) { 
 for (y = 0 .. 175 {
  // one square
  glColor3f(somecalc(z))
  glVertex3f (x,y,z)
  glVertex3f (x+1,y,z)
  glVertex3f( x+1,y+1,z)
  glVertex3f( x,y+1,z)
 }
}
glEnd

The squars are just a 2d array - the z achsis contains the true value
I colorized each square depending on the z-achsis.

Now my goal is to mark all quads with a given x value red.
Is it necessary to recreate the whole structure to change the color of one line inside my array? Dont think so (i hope).

I really have no clue how to change them afterwards :o)

Maybe another question concerning the same problem …
Is there a good docu available? Its funny to read the javadoc of the GL class, but all im able to see is “Interface to C language function”

Possible i should search for a opengl docu, but the reference is not really easy to read.
So maybeyou are able to recommend some kind of book?

thx for your help
Bernhard Neuhauser

try the tutorials at nehe: http://www.nehe.gamedev.net or you can find the ‘red book’ for free online (from opengl.org I think, but just search google).

I’m not sure what you mean when you say ‘recreate the whole structure’, but yes you will have to go through that loop you’ve shown in psuedocode again if the color changes. If the program is interactive than this should be happening > 20 times per second anyway, or maybe I misunderstand. One other thing, you won’t be able to use the return value of a single method call to change the color. Once again I’m not exactly sure what your trying to do, but for example if you want the red component to change depending on the X value and Z maps to blue and maybe Y maps to green or something, then you could change your code to look like this:


 // incomplete pseudocode
glBegin(GL.GL_QUADS)
for ( x = 0 ... 200 ) {
for (y = 0 .. 175 {
  // one square
  glColor3f(getRedValue(x), getGreenValue(y), getBlueValue(z))
  glVertex3f (x,y,z)
  glVertex3f (x+1,y,z)
  glVertex3f( x+1,y+1,z)
  glVertex3f( x,y+1,z)
}
}
glEnd

This may not be what you had in mind, bit you would probably get better performance by manipulating a color buffer and then apply it as a texture on top of one large quad.

Experimented little bit.
I drawn a simple line on the top of my surface. Works well.

thx
cybi