Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › OpenGL [Java] Depth issue
New Posts  All Forums:Forum Nav:

OpenGL [Java] Depth issue

post #1 of 3
Thread Starter 
I'm creating a bounding box marker for blocks used for construction but I'm having a problem where the lines are not passing through other blocks to the camera. When using GL11.glDisable((GL11.GL_DEPTH_TEST));
The lines appear at the back of the view when they should be seen through other objects?

I'm vaguely familiar with opengl and would like some assistance with what to do since the documentation I found doesn't really make sense without examples. Thanks.
Code:
public void drawBoundingBox(float delta)
    {
        if(isEnabled())
        {
            float px = (float)getPlayer().posX, py = (float)getPlayer().posY, pz = (float)getPlayer().posZ;
            float mx = (float)getPlayer().prevPosX, my = (float)getPlayer().prevPosY ,mz = (float)getPlayer().prevPosZ;
            float x = mx + ( px - mx ) * delta, y = my + ( py - my ) * delta, z = mz + ( pz - mz ) * delta;
            GL11.glDisable(GL11.GL_TEXTURE_2D);
            //GL11.glDisable((GL11.GL_DEPTH_TEST));
            GL11.glDisable(GL11.GL_FOG);
                for(Iterator iterator = blocks.iterator(); iterator.hasNext();) {
                    Mark got = (Mark)iterator.next();
                    mx = got.x - x - 0.5f; my = got.y - y - 0.5f; mz = got.z - z - 0.5f;
                    GL11.glBegin(GL11.GL_LINES);
                    GL11.glColor3f( 0, 1, 0 );
                    GL11.glVertex3f( mx, my, mz); GL11.glVertex3f( mx, my, mz + 1);
                    GL11.glVertex3f( mx +1, my, mz); GL11.glVertex3f( mx + 1, my, mz + 1);
                    GL11.glVertex3f( mx, my + 1, mz); GL11.glVertex3f( mx, my + 1, mz + 1);
                    GL11.glVertex3f( mx + 1, my + 1, mz); GL11.glVertex3f( mx + 1, my + 1, mz + 1);
                    GL11.glVertex3f( mx, my, mz); GL11.glVertex3f( mx, my + 1, mz);
                    GL11.glVertex3f( mx + 1, my, mz); GL11.glVertex3f( mx + 1, my + 1, mz);
                    GL11.glVertex3f( mx, my, mz + 1); GL11.glVertex3f( mx, my + 1, mz + 1);
                    GL11.glVertex3f( mx + 1, my, mz + 1); GL11.glVertex3f( mx + 1, my + 1, mz + 1);
                    GL11.glVertex3f( mx, my, mz); GL11.glVertex3f( mx + 1, my, mz);
                    GL11.glVertex3f( mx, my + 1, mz); GL11.glVertex3f( mx + 1, my + 1, mz);
                    GL11.glVertex3f( mx, my, mz + 1); GL11.glVertex3f( mx + 1, my, mz + 1);
                    GL11.glVertex3f( mx, my + 1, mz + 1); GL11.glVertex3f( mx + 1, my + 1, mz + 1);
                    GL11.glEnd();
                }

            GL11.glEnable((GL11.GL_DEPTH_TEST));
            GL11.glEnable(GL11.GL_TEXTURE_2D);
            GL11.glEnable(GL11.GL_FOG);
        }
    } 
Zardoz
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 950 @ 4.21 (HT/On) #3043A793 Rampage III GENE NVIDIA Geforce GTX 560 Ti MSI TFII @ Stock G.SKILL Ripjaws Series 8GB DDR3 1600 
Hard DriveOptical DriveOSMonitor
Intel X25-M SSD 80GB [x2] Raid 0 + Seagate 1TB Pioneer BR-Drive Win7 Ultimate 64bit Acer B273hu 
PowerCase
GE-M800A-d1 Gigabyte LIAN LI PC-A04B mATX 
  hide details  
Reply
Zardoz
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 950 @ 4.21 (HT/On) #3043A793 Rampage III GENE NVIDIA Geforce GTX 560 Ti MSI TFII @ Stock G.SKILL Ripjaws Series 8GB DDR3 1600 
Hard DriveOptical DriveOSMonitor
Intel X25-M SSD 80GB [x2] Raid 0 + Seagate 1TB Pioneer BR-Drive Win7 Ultimate 64bit Acer B273hu 
PowerCase
GE-M800A-d1 Gigabyte LIAN LI PC-A04B mATX 
  hide details  
Reply
post #2 of 3
Are you saying you want to see the lines through objects that are in front of it, kind of like how in TF2 you can see the cart outline through the wall? Best way to go about that would probably be to render the bounding box outline separately and just blend it over the scene.

If you just want the bounding box to display over the object then I'll point out that unless you've set your projection matrix up weird the z value increases as you get farther away. If the bounding box is appearing behind the object its because you're using mz + 1 when you should be using mz - 1.
    
CPUMotherboardGraphicsRAM
Core i5 4670k ASUS Maximus VI Gene Gigabyte GTX 460 1GB Kingston Hyper-X 
Hard DriveHard DriveHard DriveHard Drive
Samsung 830 OCZ Vertex 3 WD6401AALS WD5000AAKS 
CoolingOSMonitorMonitor
Noctua NH-D14 elementary OS Dell Ultrasharp U2312HM LG W2442PA-BF 
KeyboardPowerCaseMouse
Microsoft Sidewinder X4 Corsair HX750W Corsair Graphite 600T Logitech G700 
Audio
ASUS Xonar DG 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Core i5 4670k ASUS Maximus VI Gene Gigabyte GTX 460 1GB Kingston Hyper-X 
Hard DriveHard DriveHard DriveHard Drive
Samsung 830 OCZ Vertex 3 WD6401AALS WD5000AAKS 
CoolingOSMonitorMonitor
Noctua NH-D14 elementary OS Dell Ultrasharp U2312HM LG W2442PA-BF 
KeyboardPowerCaseMouse
Microsoft Sidewinder X4 Corsair HX750W Corsair Graphite 600T Logitech G700 
Audio
ASUS Xonar DG 
  hide details  
Reply
post #3 of 3
Thread Starter 
Ah thanks, but i already figured it out smile.gif, It just had to be the last thing rendered, i didn't think it worked like that since i'm new to opengl.
Zardoz
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 950 @ 4.21 (HT/On) #3043A793 Rampage III GENE NVIDIA Geforce GTX 560 Ti MSI TFII @ Stock G.SKILL Ripjaws Series 8GB DDR3 1600 
Hard DriveOptical DriveOSMonitor
Intel X25-M SSD 80GB [x2] Raid 0 + Seagate 1TB Pioneer BR-Drive Win7 Ultimate 64bit Acer B273hu 
PowerCase
GE-M800A-d1 Gigabyte LIAN LI PC-A04B mATX 
  hide details  
Reply
Zardoz
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 950 @ 4.21 (HT/On) #3043A793 Rampage III GENE NVIDIA Geforce GTX 560 Ti MSI TFII @ Stock G.SKILL Ripjaws Series 8GB DDR3 1600 
Hard DriveOptical DriveOSMonitor
Intel X25-M SSD 80GB [x2] Raid 0 + Seagate 1TB Pioneer BR-Drive Win7 Ultimate 64bit Acer B273hu 
PowerCase
GE-M800A-d1 Gigabyte LIAN LI PC-A04B mATX 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › OpenGL [Java] Depth issue