ich meinen Code auf einem Platz zur Abbildung eines Bildes bin Befestigung aber Bild ist die Abbildung nicht korrekt Bild Abbildung korrekt auf einem quadratischen
das endgültige Bild ist gefliest bekommen.
Bitte lassen Sie mich wissen, wie das zu korrigieren ist.
GLuint LoadTexture(const char * filename)
{
GLuint texture;
int width, height;
unsigned char * data;
FILE * file;
file = fopen(filename, "rb");
if (file == NULL)
{
printf("\nThe file is not found");
return 0;
}
width = 512;
height = 512;
data = (unsigned char *)malloc(width * height * 3);
//int size = fseek(file,);
fread(data, width * height * 3, 1, file);
fclose(file);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_DECAL);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_CLAMP);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height,GL_RGB, GL_UNSIGNED_BYTE, data);
free(data);
return texture;
}
/////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////// 0/12/8/8 /////////////////////////////////////////////////// ////
void drawSquare()
{
glBegin(GL_QUADS); // Each set of 4 vertices form a quad
// glColor3f(1.0f, 0.0f, 0.0f); // Red
glTexCoord2f(0.0f, 1.0f);
glVertex2f(-0.2f, 0.2f);
glTexCoord2f(1.0f, 1.0f);// x, y
glVertex2f(0.2f, 0.2f);
glTexCoord2f(1.0f, 0.0f);
glVertex2f(0.2f, -0.2f);
glTexCoord2f(0.0f, 0.0f);
glVertex2f(-0.2f, -0.2f);
glEnd();
}
/////////////////////////////////////// ////////////////////////////////////////////////////
void drawObject(void)
{
// push the current matrix
glPushMatrix();
// apply the translation
glEnable(GL_TEXTURE_2D);
GLuint texture;
texture = LoadTexture(FName);
glBindTexture (GL_TEXTURE_2D, texture);
drawSquare();
}
Ist die Breite und Höhe wirklich 512px? Das könnte es erklären – MadcoreTom
@MadcoreTom Können Sie erklären, warum? – eldo
Ich habe überprüft, das BMP-Bild ist 512 X 512 Pixel groß. –