OpenGL - Texture appears white need some help please
This's the first time i use OpenGL to apply texture. I have an issue when i try to apply a texture to a model, the texture appears white. To understand and solve this problem i simply display a square, load a texture, Gen it, bind it, set its parameters and link it to the vertices.
Before to post here, i have seen some posts and some people had also this issue. but their solutions didn't solve my problem.
here you can see the code:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <FreeImage.h>
#include <GL/glut.h>
GLuint texture1 = 0;
BYTE *byteimage;
int width;
int height;
void Display()
{
glClear(GL_COLOR_BUFFER_BIT);
glGenTextures(1, &texture1);
printf(" texture1 = %d", texture1);
glBindTexture(GL_TEXTURE_2D, texture1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, byteimage);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glBegin(GL_QUADS);
glTexCoord2d(0, 0); glVertex2d(-128, -128);
glTexCoord2d(1, 0); glVertex2d(128, -128);
glTexCoord2d(1, 1); glVertex2d(128, 128);
glTexCoord2d(0, 1); glVertex2d(-128, 128);
glEnd();
glFlush();
glutSwapBuffers();
}
int main(int arg, char **argc)
{
printf("OpenGL training is running\n\n");
glutInit(&arg, argc);
FREE_IMAGE_FORMAT format = FreeImage_GetFileType("E:\\Programation doc\\Texture\\texture22.bmp", 0);
if (format == FIF_UNKNOWN) { printf("format not found\n\n"); }
FIBITMAP* imagen = FreeImage_Load(format, "E:\\Programation doc\\Texture\\texture22.bmp");
if (!imagen) { printf(" not loaded\n\n"); }
FIBITMAP* temp = FreeImage_ConvertTo32Bits(imagen);
if (!temp) { printf("convert not executed\n\n"); }
byteimage = FreeImage_GetBits(temp);
if (temp !=0) { printf("byte saved\n\n",byteimage); }
width = FreeImage_GetWidth(temp);
height = FreeImage_GetHeight(temp);
printf("width = %d height = %d\n\n", width, height);
FreeImage_Unload(imagen);
glEnable(GL_TEXTURE_2D);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(1024, 768);
glutInitWindowPosition(100, 100);
glutCreateWindow("Square 01");
glClearColor(0.0, 0.0, 0.0, 0.0);
gluOrtho2D(-512, 512, -384, 384);
glutDisplayFunc(Display);
glutMainLoop();
return 0;
}
Thanks by advance to look at my code and take time to reply. Your help will be very aprreciable.
Posted Jun 3, 2017, 5:16 PM UTC
05