Semi Transparent front edges

Started by
3 comments, last by PaulP 22 years, 9 months ago
***WARNING OpenGL NEWBIE WARNING*** I have a small problem with my simple pyramid, after tyding up my code, i have now find that the nearest face of my test pyramid as become semi transpaent. I have switched on culling, but it is set to GL_BACK so the rearmost faces should be invisible so iam sure this is not the problem Any ideas as to why??? Thanks
Hope i make it through the day
Advertisement
Can you post the code?
----------------------------www.physicsforums.comwww.opengl.org
There is quite a bit as it is class based!!

This is a striped down version

But all of my Projection matrice and modelview matrices are within these 3 functions.

void CCamera::UpdateLocation(void)
{
CVector look;
look = m_vPos - m_vLook;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(m_vPos.m_fX, m_vPos.m_fY, m_vPos.m_fZ,
look.m_fX, look.m_fY, look.m_fZ,
m_vUp.m_fX, m_vUp.m_fY, m_vUp.m_fZ);
}

void CCamera::UpdateLens(void)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(m_fFov, m_fAspect, m_fNear, m_fFar);
glMatrixMode(GL_MODELVIEW);
}

void CCamera::SetViewPort(UINT width, UINT height)
{
if(height == 0)
height = 1;
m_fAspect = float(width)/float(height);
glViewport(0, 0, width, height);
}

and the initialisation code is in the following 2 functions

void CWinMain::OneTimeInit()
{
//Set the shading system to smooth
glShadeModel(GL_SMOOTH);

//set the backgraound colour to black
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

//prepare the depth buffer
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);

//set the perspective correction to best
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

//enable back face culling
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
}

bool CWinMain::InitOpenGLWindow(void)
{
//get the windows device context
m_hDC = GetDC(m_hWnd);
if(!m_hDC)
return false;

//setup the desired pixelformat structure
PIXELFORMATDESCRIPTOR pfd;
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 16;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;

//test the Desired pixel format
GLuint pixelformat = ChoosePixelFormat(m_hDC, &pfd);
if(!pixelformat)
return false;

//set the desired pixel format
if(!SetPixelFormat(m_hDC, pixelformat, &pfd))
return false;

//create the render context
m_hRC = wglCreateContext(m_hDC);
if(!m_hRC)
return false;

//set it to the window
if(!wglMakeCurrent(m_hDC, m_hRC))
return false;

return true;
}

The code initialisation is in the following order

CreateCamera() //pseudocode
CreateWindow() //pseudocode
OneTimeInit();
InitOpenGLWindow();
m_pCamera->SetViewPort(m_uWidth, m_uHeight);
m_pCamera->UpdateLens();


in the message loop i call the following code

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
m_pCamera->UpdateLocation();
glTranslatef(0.0f, 0.0f, -6.0f);
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 1.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f( 1.0f,-1.0f, 1.0f);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f( 1.0f,-1.0f, 1.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, -1.0f);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, -1.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(-1.0f,-1.0f, -1.0f);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(-1.0f,-1.0f,-1.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 1.0f);
glEnd();
SwapBuffers(m_hDC);

If anyone is willing to look at the whole lot (ony 2 classes) then email mne i will send them over

Thanks
Hope i make it through the day
by semitransparent do u mean a piece of the front triangle has been ''cut away'' if so try making your near clipplane smaller or move the camera further away from the pyramid

http://members.xoom.com/myBollux
No, i was getting a really weird effect, the certain triangles in the scene where being draw semi transaprent, lietraly!!

But i fixed it so thanks anyway, and no matter!!

for reference i was calling my one time scene init function before preparing the window for OpenGL, and it appears that it did not like being done this way. When i switched the function calls around so the render cotntext ect was initialised before the OpenGL preferences (such as GL_SMOOTH, and depth test stuff was set up it worked just fine!

But thanks anyway guys!!
Hope i make it through the day

This topic is closed to new replies.

Advertisement