blending problems with OpenGL

This is a discussion on blending problems with OpenGL within the Game Programming forums, part of the General Programming Boards category; im working on a simple 3d world and i am using bitmap images... i wanted to make a door/window that ...

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    4

    blending problems with OpenGL

    im working on a simple 3d world and i am using bitmap images... i wanted to make a door/window that is masked so that you can see thru the black areas of the mask... everything works except when you behind another wall you can still see the door from across the world.... i hope this makes sense. i would rather use bitmaps in this particular program. i know .tga's would be ideal but i dont want to go that route. can someone please tell me what im doing wrong?

    Code:
    int InitGL(GLvoid)										// All Setup For OpenGL Goes Here
    {
    	if (!LoadGLTextures())								// Jump To Texture Loading Routine
    	{
    		return FALSE;									// If Texture Didn't Load Return FALSE
    	}
    
    	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);				// Clear The Background Color To Black
    	glClearDepth(1.0);									// Enables Clearing Of The Depth Buffer
    	glEnable(GL_DEPTH_TEST);							// Enable Depth Testing
    	glShadeModel(GL_SMOOTH);							// Enables Smooth Color Shading
    	glEnable(GL_TEXTURE_2D);							// Enable 2D Texture Mapping
    	//glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Really Nice Perspective Calculations
    
    	return TRUE;										// Initialization Went OK
    }
    
    int DrawGLScene(GLvoid)									// Here's Where We Do All The Drawing
    {
    
    
    	srand(time(NULL));
    	int k = 0;
    
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer
    	glLoadIdentity();									// Reset The View
    
    // yrot = yrot+180;
    	if (lookupdown > 60) lookupdown = 60;
    	if (lookupdown < -60) lookupdown = -60;
    	glBindTexture(GL_TEXTURE_2D, texture[4]);
    	glRotatef(lookupdown,1.0f,0,0);
    	glRotatef(yrot,0.0f,1.0f,0.0f);
    	
    	glTranslated(x,0.0,z);
    
    	glBegin(GL_QUADS);
    		// Top Face
    		glNormal3f( 0.0f,1.0f, 0.0f);
    		glTexCoord2f(20.0f, 20.0f); glVertex3f(-20.0f, 0.75f, -20.0f);
    		glTexCoord2f(0.0f, 20.0f); glVertex3f( -2.0f, 0.75f, -20.0f);
    		glTexCoord2f(0.0f, 0.0f); glVertex3f( -2.0f, 0.75f,  -2.0f);
    		glTexCoord2f(20.0f, 0.0f); glVertex3f(-20.0f, 0.75f,  -2.0f);
    	glEnd();
    
    	glBindTexture(GL_TEXTURE_2D, texture[4]);
    	glBegin(GL_QUADS);
    		// Bottom Face
    		glNormal3f( 0.0f,-1.0f, 0.0f);
    		glTexCoord2f(20.0f, 20.0f); glVertex3f(-20.0f, -0.75f, -20.0f);
    		glTexCoord2f(0.0f, 20.0f); glVertex3f( -2.0f, -0.75f, -20.0f);
    		glTexCoord2f(0.0f, 0.0f); glVertex3f( -2.0f, -0.75f,  -2.0f);
    		glTexCoord2f(20.0f, 0.0f); glVertex3f(-20.0f, -0.75f,  -2.0f);
    	glEnd();
    
    	glTranslatef(-19.0f,0.0f,-19.0f);
    	
    	for(int i = 0; i < 9; i++)
    	{
    		for(int j = 0; j < 10; j++)
    		{
    
    
    			if(matrix[k] == 2)
    			{
    				glBindTexture(GL_TEXTURE_2D, texture[3]);
    
    				glBegin(GL_QUADS);
    					// Front Face
    					//glNormal3f( 0.0f, 0.0f, 1.0f);
    					glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -0.75f,  1.0f);
    					glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -0.75f,  1.0f);
    					glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  0.75f,  1.0f);
    					glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  0.75f,  1.0f);
    					// Back Face
    					//glNormal3f( 0.0f, 0.0f,-1.0f);
    					glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -0.75f, -1.0f);
    					glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  0.75f, -1.0f);
    					glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  0.75f, -1.0f);
    					glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -0.75f, -1.0f);
    					// Right face
    					//glNormal3f( 1.0f, 0.0f, 0.0f);
    					glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -0.75f, -1.0f);
    					glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  0.75f, -1.0f);
    					glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  0.75f,  1.0f);
    					glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -0.75f,  1.0f);
    					// Left Face
    					//glNormal3f(-1.0f, 0.0f, 0.0f);
    					glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -0.75f, -1.0f);
    					glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -0.75f,  1.0f);
    					glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  0.75f,  1.0f);
    					glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  0.75f, -1.0f);
    				glEnd();
    
    			}
    			if(matrix[k] == 1)
    			{
    					glBindTexture(GL_TEXTURE_2D, texture[6]);
    				glBegin(GL_QUADS);
    					// Front Face
    					glNormal3f( 0.0f, 0.0f, 1.0f);
    					glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -0.75f,  1.0f);
    					glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -0.75f,  1.0f);
    					glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  0.75f,  1.0f);
    					glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  0.75f,  1.0f);
    					// Back Face
    					glNormal3f( 0.0f, 0.0f,-1.0f);
    					glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -0.75f, -1.0f);
    					glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  0.75f, -1.0f);
    					glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  0.75f, -1.0f);
    					glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -0.75f, -1.0f);
    					// Right face
    					glNormal3f( 1.0f, 0.0f, 0.0f);
    					glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -0.75f, -1.0f);
    					glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  0.75f, -1.0f);
    					glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  0.75f,  1.0f);
    					glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -0.75f,  1.0f);
    					// Left Face
    					glNormal3f(-1.0f, 0.0f, 0.0f);
    					glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -0.75f, -1.0f);
    					glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -0.75f,  1.0f);
    					glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  0.75f,  1.0f);
    					glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  0.75f, -1.0f);
    				glEnd();				
    			}
    						if(matrix[k] == 3)
    			{
    
    
    
    				glBindTexture(GL_TEXTURE_2D, texture[5]);
    
    				glEnable(GL_BLEND);									// Enable Blending
    	            glDisable(GL_DEPTH_TEST);							// Disable Depth Testing
    	            glBlendFunc(GL_DST_COLOR,GL_ZERO);				// Blend Screen Color With Zero (Black)
    				glBegin(GL_QUADS);
    					// Front Face
    					//glNormal3f( 0.0f, 0.0f, 1.0f);
    					//glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -0.75f,  1.0f);
    					//glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -0.75f,  1.0f);
    					//glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  0.75f,  1.0f);
    					//glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  0.75f,  1.0f);
    					// Back Face
    					glNormal3f( 0.0f, 0.0f,-1.0f);
    					glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -0.75f, -1.0f);
    					glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  0.75f, -1.0f);
    					glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  0.75f, -1.0f);
    					glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -0.75f, -1.0f);
    					// Right face
    					//glNormal3f( 1.0f, 0.0f, 0.0f);
    					//glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -0.75f, -1.0f);
    					//glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  0.75f, -1.0f);
    					//glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  0.75f,  1.0f);
    					//glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -0.75f,  1.0f);
    					// Left Face
    					//glNormal3f(-1.0f, 0.0f, 0.0f);
    					//glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -0.75f, -1.0f);
    					//glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -0.75f,  1.0f);
    					//glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  0.75f,  1.0f);
    					//glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  0.75f, -1.0f);
    				glEnd();
    
    
    
    	
    
    					glBindTexture(GL_TEXTURE_2D, texture[2]);
                        glBlendFunc(GL_ONE, GL_ONE);					// Copy Image 1 Color To The Screen
    	
    					glBegin(GL_QUADS);
    					// Front Face
    					//glNormal3f( 0.0f, 0.0f, 1.0f);
    					//glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -0.75f,  1.0f);
    					//glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -0.75f,  1.0f);
    					//glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  0.75f,  1.0f);
    					//glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  0.75f,  1.0f);
    					// Back Face
    					glNormal3f( 0.0f, 0.0f,-1.0f);
    					glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -0.75f, -1.0f);
    					glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  0.75f, -1.0f);
    					glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  0.75f, -1.0f);
    					glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -0.75f, -1.0f);
    					// Right face
    					//glNormal3f( 1.0f, 0.0f, 0.0f);
    					//glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -0.75f, -1.0f);
    					//glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  0.75f, -1.0f);
    					//glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  0.75f,  1.0f);
    					//glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -0.75f,  1.0f);
    					// Left Face
    					//glNormal3f(-1.0f, 0.0f, 0.0f);
    					//glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -0.75f, -1.0f);
    					//glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -0.75f,  1.0f);
    					//glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  0.75f,  1.0f);
    					//glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  0.75f, -1.0f);
    				glEnd();
    				
    				
                  	glEnable(GL_DEPTH_TEST);							// Enable Depth Testing
    	            glDisable(GL_BLEND);								// Disable Blendin
    
    			}
    			k++;
    			glTranslatef(2.0f,0.0f,0.0f);
    		}
    		glTranslatef(-20.0f,0.0f,2.0f);
    	}
    
    	return TRUE;// Keep Going
    }
    Last edited by Salem; 09-21-2010 at 09:11 AM. Reason: snipped email address

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,625
    You should add alpha testing and pass the alpha function the options GL_GREATER and GL_ZERO ( i think )...
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SDL_ttf and OpenGL
    By sand_man in forum Game Programming
    Replies: 2
    Last Post: 12-01-2004, 05:06 PM
  2. OpenGL lighting
    By BabyG in forum Game Programming
    Replies: 3
    Last Post: 08-29-2004, 09:58 AM
  3. Problems with rotations with OpenGL and GLUT
    By darcome in forum Game Programming
    Replies: 13
    Last Post: 07-05-2002, 12:12 AM
  4. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 09:01 PM
  5. So.. what's the difference between DirectX and OpenGL?
    By QuestionC in forum Game Programming
    Replies: 6
    Last Post: 01-19-2002, 05:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21