PDA

View Full Version : Adding glOrtho() makes models transparent.



Zubaja
02-26-2014, 07:06 AM
hello everyone,

I'm having an issue with my Aspect Ratio. It's not so much that the Aspect Ratio is messed up; I fixed that. The weird thing is that after I added the Aspect Ratio correction through glOrtho(), all my present models (Cubes, mostly) became see-through.
At first I thought it was a culling issue, so I tried turning it off and even flip which side had to be culled. But that didn't fix it either.
Then I went and checked my Depth Buffer. I turned it off and I thought it was fixed. Untill I turned the view around; The right and back faces were still see-through.

I am unable to post any links at the moment, so I won't be able to show any visuals.
here's my code (Delphi2010):

procedure GLContext(HandleObject: TPanel);
var
DC: HDC;
RC: HGLRC;
begin
DC := GetDC(HandleObject.Handle); // Actually, you can use any windowed control here
setupPixelFormat(DC);
RC := wglCreateContext(DC); // makes OpenGL window out of DC

wglMakeCurrent(DC, RC);

GLInit(HandleObject.Width, HandleObject.Height); // initialize OpenGL
end;

procedure GLContext(HandleObject: TForm);
var
DC: HDC;
RC: HGLRC;
begin
DC := GetDC(HandleObject.Handle); // Actually, you can use any windowed control here
setupPixelFormat(DC);
RC := wglCreateContext(DC); // makes OpenGL window out of DC

wglMakeCurrent(DC, RC);

GLInit(HandleObject.Width, HandleObject.Height); // initialize OpenGL
end;

procedure GLInit(PortWidth, PortHeight: Integer);
begin
Aspect := PortWidth/PortHeight;
glViewPort(0, 0, PortWidth, portHeight);

// set viewing projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-Aspect, Aspect, -1, 1, -1, 1);
glFrustum(-0.1, 0.1, -0.1, 0.1, 0.3, 1000);

// position viewer
glMatrixMode(GL_MODELVIEW);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glDepthMask(GL_TRUE);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glDepthRange(0.0, 1.0);
end;

So now I wonder. What could cause this? I'm hoping anyone here can help me out as I've been struggling with the issue for several days now to no avail. Even Google has failed me, or I have lost the skills to Google Search decently.

Zubaja
02-27-2014, 01:59 AM
I managed to fix it through some more unconventional means; I just divided the xScale of my models by 'Aspect' and the dimensions are now the same as after 'glOrtho()'.

tdname
02-27-2014, 06:59 AM
Please check "glFrontFace()" function to set the right value for your 3D Models

Zubaja
02-28-2014, 01:30 AM
Thanks for the reply, tdname; But even setting it to GL_CW or GL_CCW doesn't fix the issue.
I still can't post any images either, because I'm getting an error whenever I try to post one.

Steven Katic
02-28-2014, 11:29 PM
Why are you still using glFrustum() aswell as glOrtho()?
What happens if you eliminate the glFrustum()?

Zubaja
03-04-2014, 12:37 AM
When I turn off flFrustum() and turn on glOrtho() I get a black screen full of nothing. So that's a strange issue aswel.
I truly have no idea where to turn with this other than simpy dividing the xScale with the Aspect.
it looks like I can finally add URLs and Images to my posts. Here's a few examples:
//---[With Ortho and Depth Buffer on]---\\
http://i1273.photobucket.com/albums/y413/Steven_Nolles/Ortho_What01_zps060bb490.png (http://s1273.photobucket.com/user/Steven_Nolles/media/Ortho_What01_zps060bb490.png.html)

//---[With Ortho on and Depth Buffer off]---\\
//--[FRONT
http://i1273.photobucket.com/albums/y413/Steven_Nolles/Ortho_Good_Mebbeh_zps51d2fb7f.png (http://s1273.photobucket.com/user/Steven_Nolles/media/Ortho_Good_Mebbeh_zps51d2fb7f.png.html)
//--[BACK
http://i1273.photobucket.com/albums/y413/Steven_Nolles/Ortho_Good_NOPE_zps76ef596d.png (http://s1273.photobucket.com/user/Steven_Nolles/media/Ortho_Good_NOPE_zps76ef596d.png.html)

Steven Katic
03-04-2014, 01:37 PM
Are those rectangles supposed to look like cubes?

I would try using less extreme vaues in glFrustum:
e.g.
glFrustum(-1,1,-1,1, 1,100);
and not call glOthro() to see what results.

Steven Katic
03-04-2014, 03:18 PM
some tips:

have you searched on something like: "opengl model inside out"

some probable causes I think of are:
(1) inconsistent winding of triangles (related to where the model(s) came from)
(2) how are you moving your "camera" around: say from the front view to back view. an inappropriate transform here on the projection matrix could be a cause