Depth Test is not Working

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
dcTom
DCEmu Junior
DCEmu Junior
Posts: 43
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Mon Feb 20, 2017 7:49 pm
Has thanked: 0
Been thanked: 0

Depth Test is not Working

Post by dcTom »

my depth-testing is not working

the program is drawing in the order of the code, not of the Z-value

im trying to draw cube/map/cube
output is cube/cube/map

quard(int x1,int x2, int y1, int y2, int add)
add is the Z-value

any idea?


Code: Select all


        glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0,640,0,480,10,-10);  
	glMatrixMode( GL_MODELVIEW);
	glLoadIdentity();
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LESS);
	glClearDepth (1.0f);
	glEnable(GL_TEXTURE_2D);
	glShadeModel(GL_FLAT);


      while (1)

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glBindTexture(GL_TEXTURE_2D, tex_cube.id);      //z=3        cube
	quard(200,440, 360, 120, 3);

	glBindTexture(GL_TEXTURE_2D, tex_cube.id);  //z=1    cube
	quard(200,440, 360, 120, 1);
	glBindTexture(GL_TEXTURE_2D, tex_map.id);  //z=2    map
	quard(64,576, 440, 40, 2);


glutSwapBuffers();

Code: Select all

void quard(int x1,int x2, int y1, int y2, int add){ 
		glBegin(GL_QUADS);
		glColor4f(1.0,1.0,1.0,1.0f);
		glTexCoord2f(0,1);
		glVertex3f(x1,y1,add);  
		glTexCoord2f(1,1);
		glVertex3f(x2,y1,add);
		glTexCoord2f(1,0);
		glVertex3f(x2,y2,add);
		glTexCoord2f(0,0);
		glVertex3f(x1,y2,add);
		glEnd();
		}
User avatar
bogglez
Moderator
Moderator
Posts: 578
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: Depth Test is not Working

Post by bogglez »

Did you compare this to desktop OpenGL?
If it's a bug, then the PVR depth test is probably not set properly.
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
dcTom
DCEmu Junior
DCEmu Junior
Posts: 43
Joined: Mon Feb 20, 2017 7:49 pm
Has thanked: 0
Been thanked: 0

Re: Depth Test is not Working

Post by dcTom »

>>Did you compare this to desktop OpenGL?

i dont have a working OGL setup atm for a pc, but im very sure it once worked fine


>>If it's a bug, then the PVR depth test is probably not set properly.

at the older versions of KOS it worked

its not urgent, so i think i have to make more tests later
dcTom
DCEmu Junior
DCEmu Junior
Posts: 43
Joined: Mon Feb 20, 2017 7:49 pm
Has thanked: 0
Been thanked: 0

Re: Depth Test is not Working

Post by dcTom »

i testet the depth test with an Dektop OGL setup and it worked fine.


i also tested it with an older KOS setup from 2013 and the depth test works there.


only with the new setup from 2017 the depthtest with Ortho doesnt work

first i thought the program render the ojects in the order when its written in the code.

but later in the game, it doesnt matter where i render it some objetcts always over some text.
User avatar
bogglez
Moderator
Moderator
Posts: 578
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: Depth Test is not Working

Post by bogglez »

In that case you seem to have found a bug in the new OpenGL implementation..
Sadly I don't have the time to test and fix this myself right now.
If you want to fix this, you can search for GL_DEPTH in kos-ports/libGL. You probably need to change some default setting or make the depth test opposite.
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
dcTom
DCEmu Junior
DCEmu Junior
Posts: 43
Joined: Mon Feb 20, 2017 7:49 pm
Has thanked: 0
Been thanked: 0

Re: Depth Test is not Working

Post by dcTom »

If you want to fix this, you can search for GL_DEPTH in kos-ports/libGL. You probably need to change some default setting or make the depth test opposite.
think thats not so easy for my

all i can find are the .h files

Code: Select all

/* Depth buffer */
#define GL_NEVER              0x0200
#define GL_LESS               0x0201
#define GL_EQUAL              0x0202
#define GL_LEQUAL             0x0203
#define GL_GREATER            0x0204
#define GL_NOTEQUAL           0x0205
#define GL_GEQUAL             0x0206
#define GL_ALWAYS             0x0207

/*
#define GL_DEPTH_TEST         0x0B71
#define GL_DEPTH_BITS         0x0D56
#define GL_DEPTH_CLEAR_VALUE  0x0B73
#define GL_DEPTH_FUNC         0x0B74
#define GL_DEPTH_RANGE        0x0B70
#define GL_DEPTH_WRITEMASK    0x0B72
#define GL_DEPTH_COMPONENT    0x1902*/

#define GL_DEPTH_TEST         0
#define GL_DEPTH_BITS         0
#define GL_DEPTH_CLEAR_VALUE  0
#define GL_DEPTH_FUNC         0
#define GL_DEPTH_RANGE        0
#define GL_DEPTH_WRITEMASK    0
#define GL_DEPTH_COMPONENT    0

so set #define GL_DEPTH_TEST 0 to 1 ???
or all?

do i have to compile something new after changing?
User avatar
bogglez
Moderator
Moderator
Posts: 578
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: Depth Test is not Working

Post by bogglez »

I assume you didn't find anything else because you ran "make install clean" for the port or you used the build all script which does that.
That will download the source code, compile and install it, then delete the code.
I think the command you need is make fetch or something.. please look it up in kos-ports.
You will get a folder with this file for example which seems relevant https://github.com/ljsebald/kos-libgl/b ... r/gl-cap.c
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
dcTom
DCEmu Junior
DCEmu Junior
Posts: 43
Joined: Mon Feb 20, 2017 7:49 pm
Has thanked: 0
Been thanked: 0

Re: Depth Test is not Working

Post by dcTom »

havent find anything until now,

but found somthing other strange
file gl-cap.c
https://github.com/ljsebald/kos-libgl/b ... r/gl-cap.c

line 111-141

Code: Select all

    GLboolean APIENTRY glIsEnabled(GLenum cap) {
    if(cap >= GL_LIGHT0 && cap <= GL_LIGHT15) return _glKosIsLightEnabled(cap & 0xFF);

    switch(cap) {
        case GL_DEPTH_TEST:
            return _glKosEnabledDepthTest() ? GL_TRUE : GL_FALSE;

        case GL_SCISSOR_TEST:
            return _glKosEnabledScissorTest() ? GL_TRUE : GL_FALSE;

        case GL_CULL_FACE:
            return _glKosEnabledFog() ? GL_TRUE : GL_FALSE;

        case GL_FOG:
            return _glKosEnabledFog() ? GL_TRUE : GL_FALSE;

        case GL_LIGHTING:
            return _glKosEnabledLighting() ? GL_TRUE : GL_FALSE;

        case GL_KOS_NEARZ_CLIPPING:
            return _glKosEnabledNearZClip() ? GL_TRUE : GL_FALSE;

        case GL_TEXTURE_2D:
            return _glKosEnabledTexture2D() ? GL_TRUE : GL_FALSE;

        case GL_BLEND:
            return _glKosEnabledBlend() ? GL_TRUE : GL_FALSE;
    }

    return GL_FALSE;
}


i'm wondering if line 122 is right

Code: Select all

case GL_CULL_FACE:
            return _glKosEnabledFog() ? GL_TRUE : GL_FALSE;
shouldnt it be

Code: Select all

case GL_CULL_FACE:
            return _glKosEnabledCulling() ? GL_TRUE : GL_FALSE;
dcTom
DCEmu Junior
DCEmu Junior
Posts: 43
Joined: Mon Feb 20, 2017 7:49 pm
Has thanked: 0
Been thanked: 0

Re: Depth Test is not Working

Post by dcTom »

what i found out

glEnable(GL_DEPTH_TEST);
glDisable(GL_DEPTH_TEST);

is not effecting the depth Test

it enable and disable GL_TEXTURE_2D
so glEnable(GL_DEPTH_TEST); makes the same like glEnable(GL_TEXTURE_2D)

glIsEnabled (GL_DEPTH_TEST); doesnt return the status of the the depth test , it returns the status of GL_TEXTURE_2D
User avatar
bogglez
Moderator
Moderator
Posts: 578
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: Depth Test is not Working

Post by bogglez »

dcTom wrote:havent find anything until now,

but found somthing other strange
file gl-cap.c
https://github.com/ljsebald/kos-libgl/b ... r/gl-cap.c

line 111-141

Code: Select all

    GLboolean APIENTRY glIsEnabled(GLenum cap) {
    if(cap >= GL_LIGHT0 && cap <= GL_LIGHT15) return _glKosIsLightEnabled(cap & 0xFF);

    switch(cap) {
        case GL_DEPTH_TEST:
            return _glKosEnabledDepthTest() ? GL_TRUE : GL_FALSE;

        case GL_SCISSOR_TEST:
            return _glKosEnabledScissorTest() ? GL_TRUE : GL_FALSE;

        case GL_CULL_FACE:
            return _glKosEnabledFog() ? GL_TRUE : GL_FALSE;

        case GL_FOG:
            return _glKosEnabledFog() ? GL_TRUE : GL_FALSE;

        case GL_LIGHTING:
            return _glKosEnabledLighting() ? GL_TRUE : GL_FALSE;

        case GL_KOS_NEARZ_CLIPPING:
            return _glKosEnabledNearZClip() ? GL_TRUE : GL_FALSE;

        case GL_TEXTURE_2D:
            return _glKosEnabledTexture2D() ? GL_TRUE : GL_FALSE;

        case GL_BLEND:
            return _glKosEnabledBlend() ? GL_TRUE : GL_FALSE;
    }

    return GL_FALSE;
}


i'm wondering if line 122 is right

Code: Select all

case GL_CULL_FACE:
            return _glKosEnabledFog() ? GL_TRUE : GL_FALSE;
shouldnt it be

Code: Select all

case GL_CULL_FACE:
            return _glKosEnabledCulling() ? GL_TRUE : GL_FALSE;
yeah that looks like a copy paste bug. Probably nobody noticed this because glIsEnabled() isn't usually called in most code. Would be nice if you made a patch (change code, test that it works, "git diff > fix_glisenabled.patch").
dcTom wrote:what i found out

glEnable(GL_DEPTH_TEST);
glDisable(GL_DEPTH_TEST);

is not effecting the depth Test

it enable and disable GL_TEXTURE_2D
so glEnable(GL_DEPTH_TEST); makes the same like glEnable(GL_TEXTURE_2D)

glIsEnabled (GL_DEPTH_TEST); doesnt return the status of the the depth test , it returns the status of GL_TEXTURE_2D
I'm not sure why you conclude that. Can you elaborate?
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
dcTom
DCEmu Junior
DCEmu Junior
Posts: 43
Joined: Mon Feb 20, 2017 7:49 pm
Has thanked: 0
Been thanked: 0

Re: Depth Test is not Working

Post by dcTom »

I'm not sure why you conclude that. Can you elaborate?
to make the search inside the source code easier i wanted to find out what exactly is not working at the depth test

so i added this line of code

Code: Select all

wert = glIsEnabled(GL_DEPTH_TEST);
printf("depth : %d \n",wert);
output was "depth: 1"

then add in my game loop a

Code: Select all

glDisable(GL_DEPTH_TEST);
output was "depth: 0"

looks all good but this is the reaktion what i saw on my screen
glEnable(GL_DEPTH_TEST); ---> Depth test is not working
glDisable(GL_DEPTH_TEST); ----> suddenly all textures are gone. i only can see the blank white rectangle

in my code i never use blank rectangle i only use it with textures. so it took a little time to find out
glDisable(GL_TEXTURE_2D);
deactvetivate textures.

so my first idea was

Code: Select all

glDisable(GL_DEPTH_TEST);  
doesnt disable the depth test. it makes the same like

Code: Select all

glDisable(GL_TEXTURE_2D);
so perhaps

Code: Select all

glEnable(GL_DEPTH_TEST);

doesnt enable the deapth test. perhaps it makes the same like

Code: Select all

glEnable(GL_TEXTURE_2D);

so i deleted
glEnable(GL_TEXTURE_2D);
from the code

result was only white rectangels.

then i add
glEnable(GL_DEPTH_TEST);
result all textures was vidible again

====> so i can activate textures with

Code: Select all

glEnable(GL_DEPTH_TEST);
or

Code: Select all

glEnable(GL_TEXTURE_2D);
the same with glDisable


so
glIsEnabled(GL_DEPTH_TEST); makes no sens
because

both

Code: Select all

glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
effects both

Code: Select all

glIsEnabled(GL_DEPTH_TEST);
and

Code: Select all

glIsEnabled(GL_TEXTURE_2D);
it looks like all funktion of GL_DEPTH_TEST is pointet to GL_TEXTURES_2D
User avatar
bogglez
Moderator
Moderator
Posts: 578
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: Depth Test is not Working

Post by bogglez »

That's messed up!

To render with the PVR a command list is used. It consists of a header followed by one or multiple triangle strips.
It seems like this header is not set up properly. Perhaps you could look into that?
In the Kos documentation it's referred to as polygon header and context (same thing in less readable format)
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
dcTom
DCEmu Junior
DCEmu Junior
Posts: 43
Joined: Mon Feb 20, 2017 7:49 pm
Has thanked: 0
Been thanked: 0

Re: Depth Test is not Working

Post by dcTom »

any hint in what file or folder i find this header?
User avatar
bogglez
Moderator
Moderator
Posts: 578
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: Depth Test is not Working

Post by bogglez »

libgl uses the code from pvr.h and related files:

http//gamedev.allusion.net/docs/kos-2.0.0/pvr_8h.html#aa3845a080ca8ad85eabd8905ad2431cf

So search the libgl code for these pvr structs for setting up the depth test and texturing.
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
dcTom
DCEmu Junior
DCEmu Junior
Posts: 43
Joined: Mon Feb 20, 2017 7:49 pm
Has thanked: 0
Been thanked: 0

Re: Depth Test is not Working

Post by dcTom »

so now its getting strange,
i was going on with some testing

i have on my laptop a fresh setup of kos

i made the test with the nehe06 demo

the depth test is working

i changed to ortho

//gluPerspective(45.0f, 640.0f / 480.0f, 0.1f, 100.0f);
glOrtho(-5,5,-5,5,10,-10);

depth test is working

i add
glDisable(GL_DEPTH_TEST);

depth test wasnt working any more

so far so good

i add
glDisable(GL_TEXTURE_2D)

in this mode i cannot see so much

but than i delete
glDisable(GL_DEPTH_TEST);
glDisable(GL_TEXTURE_2D)

from the code but still depth test is not workingh

i changed back to

gluPerspective(45.0f, 640.0f / 480.0f, 0.1f, 100.0f);
//glOrtho(-5,5,-5,5,10,-10);

depth test is working

so before i disabled texture_2d the depth test was working in ortho mode
now its not working anymore, also in the other examples.

im not sure how its possible
but it looks like

glDisable(GL_TEXTURE_2D);

makes a permanent change inside KOS
User avatar
bogglez
Moderator
Moderator
Posts: 578
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: Depth Test is not Working

Post by bogglez »

Can you please post your test case (whole file, but as few code as necessary to show the problem)? I'll look into it then.
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5666
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Depth Test is not Working

Post by BlueCrab »

dcTom wrote: im not sure how its possible
but it looks like

glDisable(GL_TEXTURE_2D);

makes a permanent change inside KOS
It's not possible.

It's more likely that you didn't actually revert all the code somehow (didn't redo all the compilation or something like that). It's also possible you've found some sort of weird GCC compiler bug. :wink:
User avatar
lerabot
Insane DCEmu
Insane DCEmu
Posts: 134
Joined: Sun Nov 01, 2015 8:25 pm
Has thanked: 2 times
Been thanked: 19 times

Re: Depth Test is not Working

Post by lerabot »

I'm also using lGl lately.
Following this closely.
dcTom
DCEmu Junior
DCEmu Junior
Posts: 43
Joined: Mon Feb 20, 2017 7:49 pm
Has thanked: 0
Been thanked: 0

Re: Depth Test is not Working

Post by dcTom »

so i was a view days off,

i couldnt replicate the the problems with the fresh install, so i hope that just the night was too long.

but i have still the problem that the depth test is not working if i use gl ortho
I'm also using lGl lately.
would be nice
if you also can make the test with gl_ortho to make sure that not my code is wrong.


so at the moment it looks like that the depth test under Kgl is working but not in the specifig case of glOrtho.

so i looked into the file https://github.com/ljsebald/kos-libgl/b ... l-matrix.c

line 266-280

Code: Select all

/* Ortho */
void glOrtho(GLfloat left, GLfloat right,
             GLfloat bottom, GLfloat top,
             GLfloat znear, GLfloat zfar) {
    OrthoMatrix[0][0] = 2.0f / (right - left);
    OrthoMatrix[1][1] = 2.0f / (top - bottom);
    OrthoMatrix[2][2] = -2.0f / (zfar - znear);
    OrthoMatrix[3][0] = -(right + left) / (right - left);;
    OrthoMatrix[3][1] = -(top + bottom) / (top - bottom);
    OrthoMatrix[3][2] = -(zfar + znear) / (zfar - znear);

    mat_load(Matrix + MatrixMode);
    mat_apply(&OrthoMatrix);
    mat_store(Matrix + MatrixMode);
}
there is a second semicolon
OrthoMatrix[3][0] = -(right + left) / (right - left);;

i think its not 100% C standart but the compile should read it without an error.

but im not sure with it

i compared the code with this reference
https://www.talisman.org/opengl-1.1/Ref ... Ortho.html

and looks ok for me
dcTom
DCEmu Junior
DCEmu Junior
Posts: 43
Joined: Mon Feb 20, 2017 7:49 pm
Has thanked: 0
Been thanked: 0

Re: Depth Test is not Working

Post by dcTom »

just a update,

its 99,9 a bug of my code,

on the pc its working,
for the dc i organized the code new.

i dont know exactly what the problem was,
but looks like the pc was little bit more tolerant with the bug.

also one of my kos systems dont work 100% so i have to reinstall it.

but on my Laptop with the latest KOS install the depth test is working now
Post Reply