Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (116)
games submitted by our members
Games in WIP (563)
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 1585 times)
0 Members and 1 Guest are viewing this topic.
Offline beaucoralk

Senior Newbie





« Posted 2011-05-31 08: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 09: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 09: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!
Legends of Yore - The Casual Retro Roguelike
Offline delt0r

JGO Knight


Medals: 27
Exp: 18 years


Computers can do that?


« Reply #3 - Posted 2011-05-31 11: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 12:19:05 »

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

JGO Knight


Medals: 27
Exp: 18 years


Computers can do that?


« Reply #5 - Posted 2011-05-31 16: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.

 

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

The first screenshot will be displayed as a thumbnail.

radar3301 (12 views)
2014-09-21 23:33:17

BurntPizza (30 views)
2014-09-21 02:42:18

BurntPizza (22 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (28 views)
2014-09-20 20:14:06

BurntPizza (32 views)
2014-09-19 03:14:18

Dwinin (48 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (102 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!