Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  A few questions about JOGL  (Read 595 times)
0 Members and 2 Guests are viewing this topic.
Offline imsoepic

JGO n00b
*

Posts: 13



« on: 2009-11-02 15:37:13 »

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;

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
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;

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
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?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
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.

Offline kaffiene

Sr. Member
**

Posts: 418
Medals: 1



« Reply #1 on: 2009-11-02 17:14:13 »

As for Q1 - look up opengl 'selection' or 'picking' on Google.  There *is* support for that kind of thing, but there's a couple of different ways you can do it.

Offline imsoepic

JGO n00b
*

Posts: 13



« Reply #2 on: 2009-11-02 18:54:44 »

As for Q1 - look up opengl 'selection' or 'picking' on Google.  There *is* support for that kind of thing, but there's a couple of different ways you can do it.



Ok thank you ill go and check.
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.083 seconds with 20 queries.