Archived

This topic is now archived and is closed to further replies.

Masking

This topic is 5514 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I read NeHe''s tutorial on Masking (tutorial 20) and tried to implement it, but ran into a few problems. I''m trying to make a tile engine and need to mask my sprites. This is my DrawGLScene:
  
int DrawGLScene(GLvoid)									// Here''s Where We Do All The Drawing

{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer

	glLoadIdentity();									// Reset The Current Modelview Matrix

	Adjust_Camera();
	gluLookAt(eyex,eyey,eyez,centerx,centery,centerz,upx,upy,upz);
	Clear_Map();
	Draw_Tiles();
	Draw_Sprite_Layer();
	Draw_Masks();
	Draw_PC();
	return TRUE;										// Everything Went OK

}
  
Clear_Map() just clears the map. Draw_Tiles() reads in a matrix of numbers from a txt file and lays a bunch of texture mapped tiles. Draw_Sprite_Layer() does the same (that''s the layer with collision detection on it). Draw_Masks() is supposed to draw the mask to the scene, and Draw_PC() is supposed to draw the sprite on screen. My problem is, I''m getting some crazy blending. The white border around the mask is still there. The black part of the mask is transparent, but the Tiles come through, the not PC. Here are my Draw_Masks and Draw_PC functions:
  
int Draw_Masks()
{
	glEnable(GL_BLEND);							// Enable Blending

	glDisable(GL_DEPTH_TEST);						// Disable Depth Testing

	glBlendFunc(GL_DST_COLOR,GL_ZERO);				// Blend Screen Color With Zero (Black)

	glBindTexture(GL_TEXTURE_2D,texture[tex_pcdownmask]);
	glBegin(GL_QUADS);
		glTexCoord2f(1.0f,1.0f); glVertex3f(float(PCcol)+1.0f,float(PCrow)+1.0f,0.0f);
		glTexCoord2f(1.0f,0.0f); glVertex3f(float(PCcol)+1.0f,float(PCrow),0.0f);
		glTexCoord2f(0.0f,0.0f); glVertex3f(float(PCcol),float(PCrow),0.0f);				//Lay the tiles

		glTexCoord2f(0.0f,1.0f); glVertex3f(float(PCcol),float(PCrow)+1.0f,0.0f);
	glEnd();

	return 1;
}

int Draw_PC()
{
	glBlendFunc(GL_ONE, GL_ONE);					// Copy Image 2 Color To The Screen



glBindTexture(GL_TEXTURE_2D,texture[tex_pcdown]);
	glBegin(GL_QUADS);
		glColor3f(1.0f,1.0f,1.0f);
		glTexCoord2f(1.0f,1.0f); glVertex3f(float(PCcol)+1.0f,float(PCrow)+1.0f,0.0f);
		glTexCoord2f(1.0f,0.0f); glVertex3f(float(PCcol)+1.0f,float(PCrow),0.0f);
		glTexCoord2f(0.0f,0.0f); glVertex3f(float(PCcol),float(PCrow),0.0f);				//Lay the tiles

		glTexCoord2f(0.0f,1.0f); glVertex3f(float(PCcol),float(PCrow)+1.0f,0.0f);
	glEnd();

	glEnable(GL_DEPTH_TEST);						// Enable Depth Testing

	glDisable(GL_BLEND);							// Disable Blending


	return 1;
}
  
Any help is greatly appreciated. Thank you.

Share this post


Link to post
Share on other sites