well, i searched, but still no depth

there is about 200 threads here that have to do with the depth beffer, but i couldnt find any help.

ok im useing borland C++ VCL for my applications, my window code comes from a tutorial, so im sure the problem is not in the creation of the window, when i compile i dont get any errors or warnings, although i get an occasional crash, float exceptions are off with the _control87();

so here is my init stuff

glViewport(0, 0, ClientWidth, ClientHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,ClientWidth/ClientHeight,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glShadeModel(GL_SMOOTH);							// Enable Smooth Shading
glDepthMask(GL_TRUE);
glClearDepth(1.0f);									// Depth Buffer Setup
glEnable(GL_DEPTH_TEST);							// Enables Depth Testing
glDepthFunc(GL_LEQUAL);								// The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Really Nice Perspective Calculations

and my draw code,
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-6.0f);
glBegin(GL_QUADS);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(-1.0f,1.0f,0.0f);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(1.0f,1.0f,0.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(1.0f,-1.0f,0.0f);
glColor3f(0.1f,0.3f,0.5f);
glVertex3f(-1.0f,-1.0f,0.0f);
glEnd();

it worked with a different program i was messing with, accually this has reverted quite a bit, just trying to get depth now, i did away with ortho, and use perspective, and added the glDepthMask(GL_TRUE); just to make sure depth was enabled.

if i set the glTranslatef(0.0f,0.0f,1.0f);
then i can see the shape, but any more on the depth and i get plank screen, this has to be a clipping problem or something, hope someone can point it out real easy.

Hi…
If you draw a single quad, enabling or not depth buffer is the same…
I don’t understand if when you say ‘depth’ you mean ‘perspective’…
Depth buffer is a method to correctly display overlapped and itersected objects. Perspective projection lets you feel the distance…
I have not here my code, but it seems to me that I move my objects of a negative value to have them in the viewing frustum.
Hope this helps you and… sorry for my poor english!
tFz

not really, see i move it -6, and i get a blank screen, then if i move it within -1 i can see the object.

I personally don’t like that your near clip plane is so close to 0. The ratio of the near and far clip planes looks reasonable however.

the glPerspective comes strait from nehe stuff, and it was working with there code, but i didnt want it to be a console app anymore, and now that i accually got the window to work, it just wont show any depth.

Does it work if you disable depth testing? If not, then it is not a depth test/depth buffer problem. If it does work, then you will need to check your pixelformat to make sure you are getting at least 16 bits for the depth buffer, and check the depth buffer range and function.

nope, i disabled it, and i get the same thing, object dissappears if i move it more than 0.1f out.

ill post all the code im trying to use
//---------------------------------------------------------------------------
#ifndef OpenGLUnitH
#define OpenGLUnitH
//---------------------------------------------------------------------------
#include <vcl\Classes.hpp>
#include <vcl\Controls.hpp>
#include <vcl\StdCtrls.hpp>
#include <vcl\Forms.hpp>
#include <gl\gl.h>
#include <gl\glu.h>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormDestroy(TObject *Sender);
void __fastcall FormResize(TObject *Sender);

private: // User declarations
HDC hdc;
HGLRC hrc;
int PixelFormat;
public: // User declarations
__fastcall TForm1(TComponent* Owner);
void __fastcall IdleLoop(TObject*, bool&);
void __fastcall RenderGLScene();
void __fastcall SetPixelFormatDescriptor();
void __fastcall SetupRC();
void __fastcall setPixelFormatDescriptor();
};
//---------------------------------------------------------------------------
extern TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

//---------------------------------------------------------------------------
#include <vcl/vcl.h>
#pragma hdrstop
#include “OpenGLUnit.h”
#include “float.h”
#include <gl\gl.h>
#include <gl\glu.h>
//---------------------------------------------------------------------------
#pragma resource ".dfm"
TForm1 Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent
Owner)
: TForm(Owner)
{
Application->OnIdle = IdleLoop;
_control87(MCW_EM, MCW_EM);
}
//---------------------------------------------------------------------------
float rquad;
//---------------------------------------------------------------------------
void __fastcall TForm1::IdleLoop(TObject
, bool& done)
{
done = false;
TForm1::RenderGLScene();
SwapBuffers(hdc);
}

void __fastcall TForm1::RenderGLScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-1.0f);
glBegin(GL_QUADS);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(-1.0f,1.0f,0.0f);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(1.0f,1.0f,0.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(1.0f,-1.0f,0.0f);
glColor3f(0.1f,0.3f,0.5f);
glVertex3f(-1.0f,-1.0f,0.0f);
glEnd();
}
void __fastcall TForm1::FormCreate(TObject *Sender)
{
hdc = GetDC(Handle);
SetPixelFormatDescriptor();
hrc = wglCreateContext(hdc);
wglMakeCurrent(hdc, hrc);
SetupRC();
}
void __fastcall TForm1::SetupRC()
{
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
ReleaseDC(hdc, NULL);
wglMakeCurrent(hdc, NULL);
wglDeleteContext(hrc);
}
void __fastcall TForm1::SetPixelFormatDescriptor()
{
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
24,
0,0,0,0,0,0,
0,0,
0,0,0,0,0,
16,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,0
};
PixelFormat = ChoosePixelFormat(hdc, &pfd);
SetPixelFormat(hdc, PixelFormat, &pfd);
}
void __fastcall TForm1::FormResize(TObject *Sender)
{
glViewport(0, 0, ClientWidth, ClientHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,ClientWidth/ClientHeight,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glDepthMask(GL_TRUE);
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
}

Now, when you say “move it more than 0.1f out”, and I see that the near clip plane is at z=0.1f That makes me think you are simply moving the object beyond the near clip plane. I can’t compile this code, and I haven’t really studied it, so I could of course be incorrect.

What im saying is, that if i make the glTranslatef(0.0f, 0.0f, 5.0f);
the shape will dissapper, the code compiles for me, and you will have to be useing borland C++ becouse of the syntax of the VCL, really its a pain to import any code to Borland, and this isnt worth the trouble.

ive tried all sorts of stuff to fix my problem, but i just cant come up with anything.

If you do glTranslate(0.0,0.0,5.0) you move the object behind you, nothing strange if you can’t see it…
About borland: I use borland builder too. If you don’t use the IDE and modify the makefile by yourself, calling it with make by the command line, you can use any code without modifying it.
tFz

sorry that was a typo, should be -5.0

if you use borland, woud you send me a simple project, like what im trying here, mabey i can find the problem like that,

EberKain@theclans.net