hello guys
i am loading two bitmaps . one is for the background whcih covers whole screen with a texture and other is small texture on it. both are loaded ok . but i want the second texture to be blend on other so that the base color of second bitmap is not visible on the background texture. i ahve tried it with glblend but doesn’t work. i have gone through NeHe game lesson 33 which does the same thing but failed
please help me out .
the code
{
int Status=FALSE; // Status Indicator
AUX_RGBImageRec *TextureImage[2]; // Create Storage Space For The Texture
memset(TextureImage,0,sizeof(void *)*2); // Set The Pointer To NULL
// Load The Bitmap, Check For Errors, If Bitmap’s Not Found Quit
if ((TextureImage[0]=LoadBMP(“Data/Heart.bmp”)) && (TextureImage[1]=LoadBMP(“Data/Sky.bmp”)))
{
Status=TRUE;
// Set The Status To TRUE
glGenTextures(2, &texture[0]); // Create The Texture
// Typical Texture Generation Using Data From The Bitmap
for (loop=0; loop<2; loop++) // Loop Through All 5 Textures
{
glBindTexture(GL_TEXTURE_2D, texture[loop]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);// ( NEW )
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[loop]->sizeX, TextureImage[loop]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[loop]->data); //( NEW )
}
}
for (loop=0; loop<2; loop++) // Loop Through All 5 Textures
{
if (TextureImage[loop]) // If Texture Exists
{
if (TextureImage[loop]->data) // If Texture Image Exists
{
free(TextureImage[loop]->data); // Free The Texture Image Memory
}
free(TextureImage[loop]); // Free The Image Structure
}
}
return Status; // Return The Status
}
int InitGL(GLvoid)
{
if (!LoadGLTextures())
{
return FALSE;
}
ShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST);// Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
//glColor4f(1.0f, 1.0f, 1.0f, 0.5); // Full Brightness. 50% Alpha
glBlendFunc(GL_SRC_ALPHA, GL_ZERO);// Enable Alpha Blending (disable alpha testing)
glEnable(GL_BLEND);// Enable Blending (disable alpha testing)
// glAlphaFunc(GL_GREATER ,0.1f); // Set Alpha Testing (disable blending)
// glEnable(GL_ALPHA_TEST);// Enable Alpha Testing (disable blending)
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
return TRUE;
}
int DrawGLScene(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity();// Reset The View
glTranslatef(xtrans,ytrans,-5.0f);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.05f, -0.05f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.05f, -0.05f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.05f, 0.05f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.05f, 0.05f, 1.0f);
glEnd();
glDisable(GL_TEXTURE_2D);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-4.0f);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[1]);
glBegin(GL_QUADS);
glTexCoord2f(1.0f,1.0f); glVertex3f( 28.0f,+0.0f,0.0f); // Top Right
glTexCoord2f(0.0f,1.0f); glVertex3f(-28.0f,+28.0f,0.0f); // Top Left
glTexCoord2f(0.0f,0.0f); glVertex3f(-28.0f,-28.0f,-50.0f); // Bottom Left
glTexCoord2f(1.0f,0.0f); glVertex3f( 28.0f,-28.0f,-50.0f); // Bottom Right
glEnd();
glDisable(GL_TEXTURE_2D);