Jump to content

  • Log In with Google      Sign In   
  • Create Account

Issue with Opaque Objects Appearing Transluscent


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 nitro glycerine   Members   -  Reputation: 103

Like
0Likes
Like

Posted 26 March 2012 - 01:06 AM

Hello!

I'm looking for some help with a little issue I'm having rendering geometry in my OpenGL engine. Not entirely sure what the issue is, but objects appear translucent when they should be entirely opaque. I've quadruple checked my OpenGL init calls, and everything seems to be correct, even referencing it against other projects which use OpenGL.

Also worth noting that draw order seems to affect this, which makes no sense. Namely, if I draw object 1, then draw object 2, you can't see 2 through 1, but you can see 1 through 2. There are some screenshots in the following album for more clarification:

http://imgur.com/a/JsvL5

I thought it might be an issue with culling, blending or depth testing.. but all of that seems to be set up properly too. Disabling the Skybox fixes the behaviour on the first cube, but if you look through the second cube into the first, the issue reappears, as previously mentioned. Also worth noting that I'm using SDL with GLEW (although no shaders are currently active).

This is probably a simple issue (or at least I hope so and I'm just completely blind), so if anyone has any thoughts or can help in any way with respect to this issue, it would be greatly appreciated. Thank you!

OpenGL Initialization Calls:
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK) < 0) { return false; }
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, settings->verticalSync ? 1 : 0);
if((m_graphics = SDL_SetVideoMode(settings->windowWidth, settings->windowHeight, 0, SDL_OPENGL | (settings->fullScreen ? SDL_FULLSCREEN : 0))) == NULL) { return false; }

glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glEnable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glDepthFunc(GL_LEQUAL);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glShadeModel(GL_SMOOTH);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glViewport(0, 0, settings->windowWidth, settings->windowHeight);

Draw Function (with unnecessary code omitted):
void Game::draw() {
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_CULL_FACE);
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(70.0f, (GLfloat) settings->windowWidth / (GLfloat) settings->windowHeight, 0.1f, 10000.0f);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	
	// draw skybox
	// setup camera
	// draw cubes
	
	glDisable(GL_CULL_FACE);
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0, settings->windowWidth, settings->windowHeight, 0);
	
	// draw text stuff
	
	SDL_GL_SwapBuffers();
}


Sponsor:

#2 FXACE   Members   -  Reputation: 182

Like
1Likes
Like

Posted 26 March 2012 - 08:11 AM

This line:
glEnable(GL_BLEND);
Use blending mode only when you really need that (but not always).
Just put this code before object (example: text) which you planned to make it transparent and when object drawing is done disable blending mode:
glDisable(GL_BLEND);

Best wishes, FXACE.

#3 nitro glycerine   Members   -  Reputation: 103

Like
0Likes
Like

Posted 26 March 2012 - 03:45 PM

Oh wow, well I hadn't realized it, but my text rendering function was re-enabling blending when I thought it was entirely disabled from the init code. I feel pretty silly about that now. Glad it's fixed though, thanks a lot for the help! :D




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS