Vertex3f's to hold properties?

Hi, im new to OpenGL for java, now id like to make a map of tiles (square 1 sided tiles) going 4848, i have done this using the following code.
int count = 0;
for(int i=0; i < 48
48; i++) {
count++;
gl.glVertex3f(AcrossTwo, DownTwo, -0.4f);
gl.glVertex3f(AcrossTwo, DownOne, -0.4f);
gl.glVertex3f(AcrossOne, DownOne, -0.4f);
gl.glVertex3f(AcrossOne, DownTwo, -0.4f);

		AcrossOne+= 1.02f;
		AcrossTwo+= 1.02f;
                    // After 48 tiles have been layed, it moves the position down and resets horizontal back to the start to lay another 48 under it.
		if(count == 48) {
			count = 0;
			DownOne+= 1.02f;
			DownTwo+= 1.02f;
			AcrossOne = 1.0f;
			AcrossTwo = 0.0f;
		}

}

Now this does show the tiles i created, except im completely lost in how i go about accessing them, lets say i click a tile on my screen, id like to be able to change that tile’s color. I know this isnt structured properly (Normally id create a Tile class, holding all it’s properties) except i don’t actually know how to access each vertex3f by a mouse click?

Thanks for whoever helps :stuck_out_tongue:

In computer graphics its called SELECTION or PICKING.

OpenGL provides built in functionality for this ( glRenderMode(GL_SELECT) ) but you must not use it as it can be slow and OpenGL themselves have said they regret implementing it in the first place.

So what to use?

  1. Colour coded picking @ http://www.lighthouse3d.com/opengl/picking/index.php3?color1
  2. Transform your 2D mouse click point (xm,ym) into a ray in your 3D world and do collision detection with each of your objects (Simple in the case of ‘tiles’) (You might use gluUnproject)

Okay, if i do the color coded picking, Lets say were using the color light green, is there 3000 different colored light greens that would look the same to the eye? even by adjusting each tile’s color up by a unnoticible notch, but 3000 times?

In your main rendering loop you draw your tiles in their “real colour” (IE they might all be white at first).

if the mouse is clicked at (x,y) {
BEFORE drawing your tiles in their “real colour” you draw them with a “colour code” that must be unique to each tile.
You then read the colour of the pixel at (x,y) and check against your list of colour codes. This tells you which tile you clicked (if any).
Finally you draw your tiles in their “real colour” so that the user never sees the strange colour codes.
}

renderLoop() {

    if (mouseClicked) {
        drawColourCodedTiles();
        int selectedTile = checkIfColourMatchesAColourCode(x,y);
        tiles[selectedTile].setColour(BLOO);
    }

    drawTiles();
}

I am tired so my answer is not very polished but hopefully it helps