Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
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  
  GL11.glRenderMode(GL11.GL_SELECT) problem :s !!  (Read 1186 times)
0 Members and 1 Guest are viewing this topic.
Offline beaucoralk

Senior Newbie





« Posted 2011-05-31 10:33:02 »

I do not know why, but when I try to use GL11.glRenderMode (GL11.GL_SELECT) to manage a viewfinder on the objects of my 3D scenes it gets me this error:
1  
2  
3  
4  
5  
6  
Exception in thread "main" org.lwjgl.opengl.OpenGLException: Invalid operation (1282)
   at org.lwjgl.opengl.Util.checkGLError(Util.java:59)
   at org.lwjgl.opengl.GL11.glRenderMode(GL11.java:2573)
   at Renderer.test(Renderer.java:117)
   at Renderer.start(Renderer.java:77)
   at Main.main(Main.java:19)


Line 117 of file Renderer.java corresponds to the line where I call to GL11.glRenderMode (GL11.GL_SELECT)!

Here is the complete code of the function:
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  
public void test(float xcam, float zcam, float ycam)
    {
        GL11.glRenderMode(GL11.GL_SELECT);
        IntBuffer viewport = BufferUtils.createIntBuffer(16);
        FloatBuffer modelview = BufferUtils.createFloatBuffer(16);
        FloatBuffer projection = BufferUtils.createFloatBuffer(16);
        FloatBuffer fDepth = BufferUtils.createFloatBuffer(1);
        FloatBuffer position = BufferUtils.createFloatBuffer(3);
       
        GL11.glGetInteger(GL11.GL_VIEWPORT, viewport);
        GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelview);
        GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projection);
       
        GL11.glReadPixels( SCREEN_WIDTH/2, viewport.get(3) - (SCREEN_HEIGHT/2), 1, 1, GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, fDepth);
        GLU.gluUnProject((float)(SCREEN_WIDTH/2), viewport.get(3) - (float)(SCREEN_HEIGHT/2), fDepth.get(), modelview, projection, viewport, position);
   
        float distMaxPick = (float)Math.sqrt(Math.pow(xcam - position.get(0), 2)+Math.pow(ycam - position.get(1), 2)+Math.pow(zcam - position.get(2), 2));
        if (distMaxPick <= 2.5*CUBESIZE)
            tabCube[(int)(position.get(0)/CUBESIZE)][(int)(position.get(2)/CUBESIZE)][(int)(position.get(1)/CUBESIZE)].aimed(basicTexPack, CUBESIZE);
   
        /*
        System.out.println("World coords at z=" + fDepth.get(0) + "are (" +
           (int)(position.get(0)/CUBESIZE) + ", " +
           (int)(position.get(1)/CUBESIZE) + ", " +
           (int)(position.get(2)/CUBESIZE)+
                                            ")");
        */

        GL11.glRenderMode(GL11.GL_RENDER);
    }
Offline beaucoralk

Senior Newbie





« Reply #1 - Posted 2011-05-31 11:18:00 »

I found it :
1  
2  
3  
        IntBuffer selectBuffer = BufferUtils.createIntBuffer(512);
        GL11.glSelectBuffer(selectBuffer);
        GL11.glRenderMode(GL11.GL_SELECT);


But strangely, now in 3D target point through the center of the screen is always in the same manner, 0 to X, 0 to Y and -0 .**** to Z.
(0, 0, -0 .***)
Why?
Offline beaucoralk

Senior Newbie





« Reply #2 - Posted 2011-05-31 11:24:06 »

Problem solved! Wink

I was calling this function after calling my function to display the HUD, the coup matrices were taking the wrong values​​.
Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline delt0r

JGO Coder


Medals: 18


Computers can do that?


« Reply #3 - Posted 2011-05-31 13:49:33 »

You should know that it is recommended to not use Select mode these days. Generally it is not such a good way to select, rather do it yourself with something like ray casting.

I have no special talents. I am only passionately curious.--Albert Einstein
Offline beaucoralk

Senior Newbie





« Reply #4 - Posted 2011-05-31 14:19:05 »

Can you tell me more about this method ? (with the code)
Offline delt0r

JGO Coder


Medals: 18


Computers can do that?


« Reply #5 - Posted 2011-05-31 18:57:23 »

Not really. You can Google. The details (aka source) depends quite strongly on the data structures used. For example i am writing a RTS, and i use a quad tree to speed up raycasting since it is quasi 2d. While if you are doing a cad program you may want to use a kd tree or perhaps a oct-tree.

Raycasting is really ray tracing. I find the ray from the "eye" through the mouse pointer and then find the closest piece of geometry that intersects it.

I have no special talents. I am only passionately curious.--Albert Einstein
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (76 views)
2013-05-17 21:29:12

alaslipknot (88 views)
2013-05-16 21:24:48

gouessej (117 views)
2013-05-16 00:53:38

gouessej (113 views)
2013-05-16 00:17:58

theagentd (125 views)
2013-05-15 15:01:13

theagentd (112 views)
2013-05-15 15:00:54

StreetDoggy (156 views)
2013-05-14 15:56:26

kutucuk (178 views)
2013-05-12 17:10:36

kutucuk (178 views)
2013-05-12 15:36:09

UnluckyDevil (186 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.171 seconds with 21 queries.