I have a few questions i can’t seem to find the answer to on the internet or in a book.
Question 1:
Does OpenGL offer any help towards mouse listening, for example, if you have rendered your “scene” and you have changed the rotations of stuff is there anything in OpenGL which will be able to relate to what is drawn and where you clicked?
For example;
Say i draw some “tiles” in JOGL using this;
public void renderTiles(GL gl)
{
gl.glStart(GL.GL_QUADS);
for (int tileX = 0; tileX < 10; tileX++)
{
for (int tileZ = 0; tileZ < 10; tileZ++)
{
gl.glVertex3f(tileX, 0, tileZ);
gl.glVertex3f(tileX + 1, 0, tileZ);
gl.glVertex3f(tileX + 1, 0, tileZ + 1);
gl.glVertex3f(tileX, 0, tileZ + 1);
}
}
gl.glEnd();
}
And then use this to set the view point;
public void setViewpoint(GL gl, GLU glu)
{
double playerX = 5; //Middle, since we had 10 tiles
double playerY = 1; //1 of the ground
double playerZ = 5; //middle again
double viewAngle = 0.0;
double xStep = Math.cos( Math.toRadians(viewAngle));
double zStep = Math.sin( Math.toRadians(viewAngle));
double xLookAt = xPlayer + (100.0 * xStep);
double yLookAt = 0.0;
double zLookAt = zPlayer + (100.0 * zStep);
float zAxis = 0.5f;
glu.gluLookAt(xPlayer, yPlayer, zPlayer, xLookAt, yLookAt, zLookAt, 0, 1, 0);
gl.glRotatef(zAxis, 0.0f, 0.0f, 1.0f);
}
Is there any methods in OpenGL to find out what one of those tiles was clicked?
Question 2:
For the following code sample, how would i apply a texture?
Ive tried all the examples, for instance getting a 2d image, loading it via TextureIO.read, setting gl.glEnable(GL.GL_TEXTURE_2D);
And then using the TextureCoords and gl.glTexCoords2f(tc details); but it still dosn’t seem to work for me =s.
Question 3:
What is wrong with the following code?
if(drawVerts)
{
gl.glBegin(GL.GL_QUADS);
gl.glColor3f(0.0f, 0.0f, 0.5f);
for (Tile t : tileMap)
{
TileVertex[] vertices = t.getVertices();
for (int i = 0; i < 4; i++)
{
float xMinus = vertices[i].getX() - 0.05f;
float yMinus = vertices[i].getY() - 0.1f; //Starts below
float zMinus = vertices[i].getZ() - 0.05f;
float xPlus = vertices[i].getX() + 0.05f;
float yPlus = vertices[i].getY();
float zPlus = vertices[i].getZ() + 0.05f;
gl.glVertex3f(xPlus, yPlus, zPlus);
gl.glVertex3f(xPlus, yMinus, zPlus);
gl.glVertex3f(xPlus, yMinus, zMinus);
gl.glVertex3f(xPlus, yPlus, zMinus);
//
gl.glVertex3f(xPlus, yPlus, zMinus);
gl.glVertex3f(xPlus, yMinus, zMinus);
gl.glVertex3f(xMinus, yMinus, zMinus);
gl.glVertex3f(xMinus, yPlus, zMinus);
//
gl.glVertex3f(xMinus, yPlus, zMinus);
gl.glVertex3f(xMinus, yMinus, zMinus);
gl.glVertex3f(xMinus, yMinus, zPlus);
gl.glVertex3f(xMinus, yPlus, yPlus);
//
gl.glVertex3f(xMinus, yPlus, zPlus);
gl.glVertex3f(xMinus, yMinus, zPlus);
gl.glVertex3f(xPlus, yMinus, zPlus);
gl.glVertex3f(xPlus, yPlus, zPlus);
//
gl.glVertex3f(xMinus, yPlus, zMinus);
gl.glVertex3f(xMinus, yPlus, zPlus);
gl.glVertex3f(xPlus, yPlus, zPlus);
gl.glVertex3f(xPlus, yPlus, zMinus);
//
gl.glVertex3f(xMinus, yMinus, zPlus);
gl.glVertex3f(xMinus, yMinus, zMinus);
gl.glVertex3f(xPlus, yMinus, zMinus);
gl.glVertex3f(xPlus, yMinus, zPlus);
}
}
gl.glEnd();
}
Now, that code to me looks fine, it’s ment to draw the vertices of a tile, which there are 4 for each tile, but on a straight grid like system i get this problem:
IMAGE LINK: http://i38.tinypic.com/ddm1x0.jpg
I have checked the code and can’t see why it does it.
__
__
Thank you for any help i recieve, like i have already stated, i have an OpenGL book (it’s for c++ because i couldn’t find a java one) but i can’t find anything to do with what i need, apart from the textures, but everything i try still dosn’t work and ive been googling the problems for about an hour, i also put them on forums.sun.com but i havn’t had a reply in a whole day.