Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (429)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (468)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  A few questions about JOGL  (Read 830 times)
0 Members and 1 Guest are viewing this topic.
Offline imsoepic

Senior Newbie





« Posted 2009-11-02 21: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
« Reply #1 - Posted 2009-11-02 23: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

Senior Newbie





« Reply #2 - Posted 2009-11-03 00: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]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

theagentd (6 views)
2014-04-24 23:00:44

xsi3rr4x (83 views)
2014-04-15 18:08:23

BurntPizza (75 views)
2014-04-15 03:46:01

UprightPath (86 views)
2014-04-14 17:39:50

UprightPath (69 views)
2014-04-14 17:35:47

Porlus (86 views)
2014-04-14 15:48:38

tom_mai78101 (109 views)
2014-04-10 04:04:31

BurntPizza (169 views)
2014-04-08 23:06:04

tom_mai78101 (265 views)
2014-04-05 13:34:39

trollwarrior1 (217 views)
2014-04-04 12:06:45
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!