예제 #1
0
void DrawBitmap(Bitmap &b, Rect& rect, int x, int y)
{
	glPushMatrix();
	glTranslatef((float)x,(float)y,0);
	////enable textures and set up automatic texture coordinate generation
	glBindTexture(GL_TEXTURE_2D, b.GetTexture());  
	glEnable(GL_TEXTURE_2D);

	glColor4f(1.0f,1.0f,1.0f,1.0f);

	//Define how alpha blending will work and enable alpha blending.
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_BLEND);

	float tx1 = min(1.0f, (float)rect.X / (float)b.GetWidth());
	float ty1 = min(1.0f, (float)rect.Y / (float)b.GetHeight());

	float q = ((float)(rect.Width)/((float)b.GetWidth()));
	float tx2 = min(1.0f, tx1 + q);

	float f = (float)(rect.Height)/((float)b.GetHeight());
	float ty2 = min(1.0f, (ty1 + f) );



	glPolygonMode(GL_FRONT_AND_BACK, GL_POLYGON);
	glBegin(GL_QUADS);
            glTexCoord2f(tx1, 1-ty1); glVertex2f(0.0f, 0.0f);
			glTexCoord2f(tx1, 1-ty2); glVertex2f(0.0f, (float)rect.Height);
            glTexCoord2f(tx2, 1-ty2); glVertex2f((float)rect.Width, (float)rect.Height);
            glTexCoord2f(tx2, 1-ty1); glVertex2f((float)rect.Width, 0.0f);
	glEnd();
	glDisable(GL_TEXTURE_2D);
	glPopMatrix();
}
예제 #2
0
void DrawBitmap(Bitmap &b, int x, int y, int w, int h)
{
	glPushMatrix();
	glTranslatef((float)x,(float)y,0);
	////enable textures and set up automatic texture coordinate generation
	glBindTexture(GL_TEXTURE_2D, b.GetTexture());  
	glEnable(GL_TEXTURE_2D);

	glColor4f(1.0f,1.0f,1.0f,1.0f);

	//Define how alpha blending will work and enable alpha blending.
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_BLEND);

	glPolygonMode(GL_FRONT_AND_BACK, GL_POLYGON);
	glBegin(GL_QUADS);
            glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, 0.0f);
            glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, (float)h);
            glTexCoord2f(1.0f, 0.0f); glVertex2f((float)w, (float)h);
            glTexCoord2f(1.0f, 1.0f); glVertex2f((float)w, 0.0f);
	glEnd();
	glDisable(GL_TEXTURE_2D);
	glPopMatrix();
}