1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
GLuint LoadTexture(const char * pic, int width, int height)
{
GLuint Texture;
BYTE * data;
FILE * picfile;
picfile = fopen(pic, "rb");
if (picfile == NULL)
return 0;
data = (BYTE *)malloc(width * height * 3);
fread(data, width * height, 3, picfile);
fclose(picfile);
glGenTextures(1, &Texture);
glBindTexture(GL_TEXTURE_2D, Texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
free(data);
return Texture;
}
void Games()
{
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
GLuint myTex;
myTex = LoadTexture("boom.bmp", 75, 75);
glBindTexture(GL_TEXTURE_2D, myTex);
glBegin(GL_POLYGON);
glTexCoord2f(37.5, 37.5); glVertex3f(37.5, 37.5, 0.0);
glTexCoord2f(-37.5, 37.5); glVertex3f(-37.5, 37.5, 0.0);
glTexCoord2f(-37.5, -37.5); glVertex3f(-37.5, -37.5, 0.0);
glTexCoord2f(37.5, -37.5); glVertex3f(37.5, -37.5, 0.0);
glEnd();
glDisable(GL_TEXTURE_2D);
}
|