Original Post
Hi,
From the http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=30 I am just using the bmp loader file in my game to texture sky cubes. It is loading the textures but after just 4-5 seconds the application exits and say File not found.
Here is the loading function:
void LoadSkyTexture() {
// Load Texture
Image *image1, *image2, *image3, *image4, *image5, *image6;
// allocate space for texture
image1 = (Image *) malloc(sizeof(Image));
if (image1 == NULL) {
printf("Error allocating space for image");
exit(0);
}
image2 = (Image *) malloc(sizeof(Image));
if (image2 == NULL) {
printf("Error allocating space for image");
exit(0);
}
image3 = (Image *) malloc(sizeof(Image));
if (image3 == NULL) {
printf("Error allocating space for image");
exit(0);
}
image4 = (Image *) malloc(sizeof(Image));
if (image4 == NULL) {
printf("Error allocating space for image");
exit(0);
}
image5 = (Image *) malloc(sizeof(Image));
if (image5 == NULL) {
printf("Error allocating space for image");
exit(0);
}
image6 = (Image *) malloc(sizeof(Image));
if (image6 == NULL) {
printf("Error allocating space for image");
exit(0);
}
if (!ImageLoad("skybox/front.bmp", image1)) {
exit(1);
}
if (!ImageLoad("skybox/back.bmp", image2)) {
exit(1);
}
if (!ImageLoad("skybox/up.bmp", image3)) {
exit(1);
}
if (!ImageLoad("skybox/down.bmp", image4)) {
exit(1);
}
if (!ImageLoad("skybox/left.bmp", image5)) {
exit(1);
}
if (!ImageLoad("skybox/right.bmp", image6)) {
exit(1);
}
// Create Texture 1
glGenTextures(1, &Skytexture[0]);
glBindTexture(GL_TEXTURE_2D, Skytexture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, 3, image1->sizeX, image1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image1->data);
// Create Texture 2
glGenTextures(1, &Skytexture[1]);
glBindTexture(GL_TEXTURE_2D, Skytexture[1]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, 3, image2->sizeX, image2->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image2->data);
// Create Texture 3
glGenTextures(1, &Skytexture[2]);
glBindTexture(GL_TEXTURE_2D, Skytexture[2]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, 3, image3->sizeX, image3->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image3->data);
// Create Texture 4
glGenTextures(1, &Skytexture[3]);
glBindTexture(GL_TEXTURE_2D, Skytexture[3]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, 3, image4->sizeX, image4->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image4->data);
// Create Texture 5
glGenTextures(1, &Skytexture[4]);
glBindTexture(GL_TEXTURE_2D, Skytexture[4]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, 3, image5->sizeX, image5->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image5->data);
// Create Texture 6
glGenTextures(1, &Skytexture[5]);
glBindTexture(GL_TEXTURE_2D, Skytexture[5]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, 3, image6->sizeX, image6->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image6->data);
free(image1->data);
free(image1);
free(image2->data);
free(image2);
free(image3->data);
free(image3);
free(image4->data);
free(image4);
free(image5->data);
free(image5);
free(image6->data);
free(image6);
};
Here is the binding to the quads:
void RenderSkybox(void) {
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
// enable texturing
glEnable(GL_TEXTURE_2D);
LoadSkyTexture();
// front
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, Skytexture[0]);
glColor3f(1, 1, 1);
glRotatef(sky_rot_FT,0.f,0.0f,1.0f);
Primitives.DrawSkybox_FT();
glPopMatrix();
// back
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, Skytexture[1]);
glColor3f(1, 1, 1);
glRotatef(sky_rot_BK,0.f,0.0f,1.0f);
Primitives.DrawSkybox_BK();
glPopMatrix();
// up
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, Skytexture[2]);
glColor3f(1, 1, 1);
glRotatef(sky_rot_UP,0.f,1.0f,0.0f);
Primitives.DrawSkybox_UP();
glPopMatrix();
// down
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, Skytexture[3]);
glColor3f(1, 1, 1);
glRotatef(sky_rot_DN,0.f,1.0f,0.0f);
Primitives.DrawSkybox_DN();
glPopMatrix();
// left
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, Skytexture[4]);
glColor3f(1, 1, 1);
glRotatef(sky_rot_LT,1.f,0.0f,0.0f);
Primitives.DrawSkybox_LT();
glPopMatrix();
// right
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, Skytexture[5]);
glColor3f(1, 1, 1);
glRotatef(sky_rot_RT,1.f,0.0f,0.0f);
Primitives.DrawSkybox_RT();
glPopMatrix();
glEnable(GL_DEPTH_TEST);
glDisable(GL_TEXTURE_2D);
}
Could someone kindly tell me what i m doing wrong? Sorry I dont know html much.
Thanks in advance
Regards
From the http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=30 I am just using the bmp loader file in my game to texture sky cubes. It is loading the textures but after just 4-5 seconds the application exits and say File not found.
Here is the loading function:
void LoadSkyTexture() {
// Load Texture
Image *image1, *image2, *image3, *image4, *image5, *image6;
// allocate space for texture
image1 = (Image *) malloc(sizeof(Image));
if (image1 == NULL) {
printf("Error allocating space for image");
exit(0);
}
image2 = (Image *) malloc(sizeof(Image));
if (image2 == NULL) {
printf("Error allocating space for image");
exit(0);
}
image3 = (Image *) malloc(sizeof(Image));
if (image3 == NULL) {
printf("Error allocating space for image");
exit(0);
}
image4 = (Image *) malloc(sizeof(Image));
if (image4 == NULL) {
printf("Error allocating space for image");
exit(0);
}
image5 = (Image *) malloc(sizeof(Image));
if (image5 == NULL) {
printf("Error allocating space for image");
exit(0);
}
image6 = (Image *) malloc(sizeof(Image));
if (image6 == NULL) {
printf("Error allocating space for image");
exit(0);
}
if (!ImageLoad("skybox/front.bmp", image1)) {
exit(1);
}
if (!ImageLoad("skybox/back.bmp", image2)) {
exit(1);
}
if (!ImageLoad("skybox/up.bmp", image3)) {
exit(1);
}
if (!ImageLoad("skybox/down.bmp", image4)) {
exit(1);
}
if (!ImageLoad("skybox/left.bmp", image5)) {
exit(1);
}
if (!ImageLoad("skybox/right.bmp", image6)) {
exit(1);
}
// Create Texture 1
glGenTextures(1, &Skytexture[0]);
glBindTexture(GL_TEXTURE_2D, Skytexture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, 3, image1->sizeX, image1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image1->data);
// Create Texture 2
glGenTextures(1, &Skytexture[1]);
glBindTexture(GL_TEXTURE_2D, Skytexture[1]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, 3, image2->sizeX, image2->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image2->data);
// Create Texture 3
glGenTextures(1, &Skytexture[2]);
glBindTexture(GL_TEXTURE_2D, Skytexture[2]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, 3, image3->sizeX, image3->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image3->data);
// Create Texture 4
glGenTextures(1, &Skytexture[3]);
glBindTexture(GL_TEXTURE_2D, Skytexture[3]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, 3, image4->sizeX, image4->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image4->data);
// Create Texture 5
glGenTextures(1, &Skytexture[4]);
glBindTexture(GL_TEXTURE_2D, Skytexture[4]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, 3, image5->sizeX, image5->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image5->data);
// Create Texture 6
glGenTextures(1, &Skytexture[5]);
glBindTexture(GL_TEXTURE_2D, Skytexture[5]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, 3, image6->sizeX, image6->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image6->data);
free(image1->data);
free(image1);
free(image2->data);
free(image2);
free(image3->data);
free(image3);
free(image4->data);
free(image4);
free(image5->data);
free(image5);
free(image6->data);
free(image6);
};
Here is the binding to the quads:
void RenderSkybox(void) {
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
// enable texturing
glEnable(GL_TEXTURE_2D);
LoadSkyTexture();
// front
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, Skytexture[0]);
glColor3f(1, 1, 1);
glRotatef(sky_rot_FT,0.f,0.0f,1.0f);
Primitives.DrawSkybox_FT();
glPopMatrix();
// back
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, Skytexture[1]);
glColor3f(1, 1, 1);
glRotatef(sky_rot_BK,0.f,0.0f,1.0f);
Primitives.DrawSkybox_BK();
glPopMatrix();
// up
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, Skytexture[2]);
glColor3f(1, 1, 1);
glRotatef(sky_rot_UP,0.f,1.0f,0.0f);
Primitives.DrawSkybox_UP();
glPopMatrix();
// down
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, Skytexture[3]);
glColor3f(1, 1, 1);
glRotatef(sky_rot_DN,0.f,1.0f,0.0f);
Primitives.DrawSkybox_DN();
glPopMatrix();
// left
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, Skytexture[4]);
glColor3f(1, 1, 1);
glRotatef(sky_rot_LT,1.f,0.0f,0.0f);
Primitives.DrawSkybox_LT();
glPopMatrix();
// right
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, Skytexture[5]);
glColor3f(1, 1, 1);
glRotatef(sky_rot_RT,1.f,0.0f,0.0f);
Primitives.DrawSkybox_RT();
glPopMatrix();
glEnable(GL_DEPTH_TEST);
glDisable(GL_TEXTURE_2D);
}
Could someone kindly tell me what i m doing wrong? Sorry I dont know html much.
Thanks in advance
Regards