Texture Issues

Hey guys,

I need some help as this is driving me nuts. I want to texture a quadric sphere, I have a header file and a .cpp file with the instructions to load a .bmp file, but all I get is a blank screen and no errors. I will include what I have so far:

fileFunctions.h

unsigned char *LoadBitmapFile(char *filename, BITMAPINFOHEADER *bitmapInfoHeader);

fileFunctions.cpp

#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include “fileFunctions.h”

// Returns a pointer to the bitmap image of the bitmap specified
// by filename. Also returns the bitmap header information.
// No support for 8-bit bitmaps.
unsigned char *LoadBitmapFile(char *filename, BITMAPINFOHEADER *bitmapInfoHeader)
{
FILE *filePtr;
BITMAPFILEHEADER bitmapFileHeader;
unsigned char bitmapImage;
int imageIdx = 0;
unsigned char tempRGB;
filePtr = fopen(filename, “rb”);
if (filePtr == NULL) return NULL;
fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr);
fread(bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, filePtr);
fseek(filePtr, bitmapFileHeader.bfOffBits, SEEK_SET);
bitmapImage = (unsigned char
)malloc(bitmapInfoHeader->biSizeImage);
fread(bitmapImage, 1, bitmapInfoHeader->biSizeImage, filePtr);
for (imageIdx = 0; imageIdx < bitmapInfoHeader->biSizeImage; imageIdx+=3)
{
tempRGB = bitmapImage[imageIdx];
bitmapImage[imageIdx] = bitmapImage[imageIdx + 2];
bitmapImage[imageIdx + 2] = tempRGB;

}

}

Planets.cpp

#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include “fileFunctions.h”

using namespace std;

GLUquadricObj mercury;
GLuint txtMercury;
BITMAPINFOHEADER bitmapInfoHeader;
unsigned char
bitmapData;

void display() {
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glBindTexture(GL_TEXTURE_2D,txtMercury);
gluSphere(mercury, 1.0, 32, 32);
glFlush();
}

void init(void) {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-4.0,4.0,-4.0,4.0,0.0,10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_TEXTURE_2D);
bitmapData = LoadBitmapFile(“Venus.bmp”,&bitmapInfoHeader);
glGenTextures(1,&txtMercury);
glBindTexture(GL_TEXTURE_2D,txtMercury);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,bitmapInfoHeader.biWidth,bitmapInfoHeader.biHeight,0,GL_RGB,GL_UNSIGNED_BYTE, bitmapData);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
mercury=gluNewQuadric();
gluQuadricTexture(mercury,GLU_TRUE);
gluQuadricDrawStyle(mercury,GLU_FILL);
gluQuadricNormals(mercury,GLU_SMOOTH);
free(bitmapData);
}

int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800,800);
glutInitWindowPosition(100,100);
glutCreateWindow(“20918381 Planets”);
init();
glutDisplayFunc(display);
glutMainLoop();
}

Hi,
You are missing the return statement from your loadbitmapFile func.

return bitmapImage;

OMG thank you so much Mobeen thats really helped!

I also have a question please Mobeen or anyone:

1). How do load and apply textures to other quadric shapes within the same program. As i am trying to design a solar system and cant seem to apply or load different textures.

You would need to create the texture objects first. Lets say u have three textures to load, image0.bmp, image1.bmp and image2.bmp. We use


GLuint textureID[3];
glGenTextures(3, textureID);
for(int i=0;i<3;i++) {
unsigned char* bitmapData = LoadImage("image"+i+".bmp");
glBindTexture(GL_TEXTURE_2D,textureID[i]);
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_CLAMP); 
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,bitmapInfoHeader.biWidth,bitmapInfoHeader.biHeight,0,GL_RGB,GL_UNSIGNED_BYTE, bitmapData);
free(bitmapData);//if u use malloc to allocate the bitmapData 
}

Then in your render loop you would apply the appropriate transform and before drawing the quadric bind its texture doing somthing like this


//apply modelview transform
for(int i=0;i<3;i++) 
{
  //apply object's transform matrix here
  glBindTexture(GL_TEXTURE_2D, textureID[i]);
   //draw object here
}

Hope this helps,
Mobeen

Hey Mobeen,

Wonderful, thanks so much…I just have 1 little problem. I now get an error saying "92 C:\Users\Martin\Desktop\planets\planets.cpp invalid operands of types const char*' andconst char[5]’ to binary `operator+’ "

Here is my code after ur recommendations:

#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include “fileFunctions.h”

using namespace std;

GLfloat viewangle = 0, tippangle = 0;
GLfloat xAngle = 0.0, yAngle = 0.0, zAngle = 0.0;
GLfloat d[3] = {0.1, 0.1, 0.1};

float angle[6];

GLUquadricObj *sun;
GLUquadricObj *mercury;
GLuint textureID[9];

BITMAPINFOHEADER bitmapInfoHeader;
unsigned char* bitmapData;

void drawSun(){
glBindTexture(GL_TEXTURE_2D,textureID[0]);
glRotatef(angle[0],0.0,1,0.0);
gluSphere(sun, 1.0, 32, 32);
}
void drawMercury(){
glBindTexture(GL_TEXTURE_2D,textureID[1]);
glRotatef(angle[1],0.0,1,0.0);
gluSphere(mercury, 0.5, 32, 32);
}

void rotate(){
angle[0]+=0.005;
if (angle[0]>360)angle[0]-=360;
angle[1]+= 0.05;
if (angle[1]>360) angle[1]-=360;
glutPostRedisplay();
}

void Special_Keys (int key, int x, int y)
{
switch (key) {
case GLUT_KEY_LEFT : viewangle -= 5; break;
case GLUT_KEY_RIGHT: viewangle += 5; break;
case GLUT_KEY_UP : tippangle -= 5; break;
case GLUT_KEY_DOWN : tippangle += 5; break;
}
glutPostRedisplay();
}
void keyPressed(unsigned char key, int x, int y){
switch (key) {
case ‘j’ : d[0] += 0.1; break;
case ‘k’ : d[1] += 0.1; break;
case ‘l’ : d[2] += 0.1; break;

   case 'x' : xAngle += 5;  break;
   case 'y' : yAngle += 5;  break;
   case 'z' : zAngle += 5;  break;

}
glutPostRedisplay();

}

void display() {
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable (GL_DEPTH_TEST);
glLoadIdentity();
glRotatef (tippangle, 1,0,0); // Up and down arrow keys ‘tip’ view.
glRotatef (viewangle, 0,1,0); // Right/left arrow keys ‘turn’ view.
glPushMatrix ();
glTranslatef (d[0], d[1], d[2]); // Move box down X axis.
drawSun();
glTranslatef(0.5,0.5,-2);
drawMercury();
glRotatef (zAngle, 0,0,1);
glRotatef (yAngle, 0,1,0);
glRotatef (xAngle, 1,0,0);
glPopMatrix ();
glFlush();
glutSwapBuffers();
}

void init(void) {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-4.0,4.0,-4.0,4.0,0.0,10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_TEXTURE_2D);
glGenTextures(9, textureID);
for(int i=0;i<9;i++) {
unsigned char*bitmapData = LoadImage(“image”+i+".bmp");
glBindTexture(GL_TEXTURE_2D,textureID[i]);
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_CLAMP);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,bitmapInfoHeader.biWidth,bitmapInfoHeader.biHeight,0,GL_RGB,GL_UNSIGNED_BYTE, bitmapData);
free(bitmapData);
}
sun=gluNewQuadric();
mercury=gluNewQuadric();
gluQuadricTexture(sun,GLU_TRUE);
gluQuadricDrawStyle(sun,GLU_FILL);
gluQuadricNormals(sun,GLU_SMOOTH);
gluQuadricTexture(mercury,GLU_TRUE);
gluQuadricDrawStyle(mercury,GLU_FILL);
gluQuadricNormals(mercury,GLU_SMOOTH);

}

int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800,800);
glutInitWindowPosition(100,100);
glutCreateWindow(“20918381 Planets”);
angle[0]=0;
angle[1]=0;
glutIdleFunc(rotate);
glutKeyboardFunc(keyPressed);
glutSpecialFunc(Special_Keys);
init();
glutDisplayFunc(display);
glutMainLoop();
}

Hi,
yeah i just passed in the info. so that u get the idea. The reason u get this error is because the func. expects a char* so u must pass in a char pointer and we are trying to add two const char* which is wrong. Instead u should do this,
replace this line

unsigned char*bitmapData = LoadImage("image"+i+".bmp");

with this


char imageName[50]={'\0'};
sprintf(imageName, "image%d.bmp",i);
unsigned char* bitmapData = LoadImage(imageName);

This assumes that the image names are less than 50 chars.

See if this sorts out your problem.

Regards,
Mobeen

OMG another error now, ill post it and as you’ve already guessed only been working on openGL for a short while as a 2nd year uni student :slight_smile:

94 C:\Users\Martin\Desktop\planets\planets.cpp cannot convert char*' toHINSTANCE__’ for argument 1' tovoid LoadImageA(HINSTANCE__, const CHAR, UINT, int, int, UINT)’

CHange your func. name from LoadImage to MyLoadImage or anything else. It is conflicting with the WInAPI func. of the same name.

ive tried changing unsigned char* bitmapData = LoadImage(imageName); to MyLoadImage as suggested, but a new error shows that the function needs to be declared

regards

Martin

p.s thank you so much for your help so far mobeen

Ofcourse change the name in the whole source code not just the call that means the definition also.

OK ty mobeen, but having trouble still as i am not sure how to declare this? is is global? or a correction in my header file? :slight_smile:

correct the func. name not only in the header file but also in the cpp file where u call it.

The best way to do this is go to do a find/replace of all occurences of LoadImage to MyLoadImage in the entire solution. In visual studio press Ctrl+H and then select entire solution from the drop down combobox. Then press replace all. This should do it.

Ok i checked my files and the only reference to LoadImage is within my main.cpp, which we added. Maybe check my fileFunctions.h and cpp file again as they use LoadBitmapFile, and it has an extra declaration with the header file:

fileFunctions.h:

unsigned char *LoadBitmapFile(char *filename, BITMAPINFOHEADER *bitmapInfoHeader);

fileFunctions.cpp

#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include “fileFunctions.h”

unsigned char *LoadBitmapFile(char *filename, BITMAPINFOHEADER *bitmapInfoHeader)
{
FILE *filePtr;
BITMAPFILEHEADER bitmapFileHeader;
unsigned char bitmapImage;
int imageIdx = 0;
unsigned char tempRGB;
filePtr = fopen(filename, “rb”);
if (filePtr == NULL) return NULL;
fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr);
fread(bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, filePtr);
fseek(filePtr, bitmapFileHeader.bfOffBits, SEEK_SET);
bitmapImage = (unsigned char
)malloc(bitmapInfoHeader->biSizeImage);
fread(bitmapImage, 1, bitmapInfoHeader->biSizeImage, filePtr);
for (imageIdx = 0; imageIdx < bitmapInfoHeader->biSizeImage; imageIdx+=3)
{
tempRGB = bitmapImage[imageIdx];
bitmapImage[imageIdx] = bitmapImage[imageIdx + 2];
bitmapImage[imageIdx + 2] = tempRGB;
}
return bitmapImage;
}

also I am using DEV c++, as I have no clue on how to get Visual Studio to run openGL, I do have visual studio 2008 installed but only used it for .net applications

just as an extra addition, this my for loop now with the loadbitmapfile linked from my header files. but now i get the quads and no materials

for(int i=0;i<9;i++) {
glBindTexture(GL_TEXTURE_2D,textureID[i]);
char imageName[50]={’\0’};
sprintf(imageName, “image%d.bmp”,i);
unsigned char* bitmapData = LoadBitmapFile(imageName, &bitmapInfoHeader);
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_CLAMP);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,bitmapInfoHeader.biWidth,bitmapInfoHeader.biHeight,0,GL_RGB,GL_UNSIGNED_BYTE, bitmapData);
free(bitmapData);
}

I dont understand why a name change would cause the code to not work now. Could u post the whole code the way u did when u post it initially. May be u have messed the code elsewhere.

this was my initial code

fileFunctions.h

unsigned char *LoadBitmapFile(char *filename, BITMAPINFOHEADER *bitmapInfoHeader);

fileFunctions.cpp

#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include “fileFunctions.h”

// Returns a pointer to the bitmap image of the bitmap specified
// by filename. Also returns the bitmap header information.
// No support for 8-bit bitmaps.
unsigned char *LoadBitmapFile(char *filename, BITMAPINFOHEADER *bitmapInfoHeader)
{
FILE *filePtr;
BITMAPFILEHEADER bitmapFileHeader;
unsigned char bitmapImage;
int imageIdx = 0;
unsigned char tempRGB;
filePtr = fopen(filename, “rb”);
if (filePtr == NULL) return NULL;
fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr);
fread(bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, filePtr);
fseek(filePtr, bitmapFileHeader.bfOffBits, SEEK_SET);
bitmapImage = (unsigned char
)malloc(bitmapInfoHeader->biSizeImage);
fread(bitmapImage, 1, bitmapInfoHeader->biSizeImage, filePtr);
for (imageIdx = 0; imageIdx < bitmapInfoHeader->biSizeImage; imageIdx+=3)
{
tempRGB = bitmapImage[imageIdx];
bitmapImage[imageIdx] = bitmapImage[imageIdx + 2];
bitmapImage[imageIdx + 2] = tempRGB;

}
return bitmapImage;
}

Planets.cpp

#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include “fileFunctions.h”

using namespace std;

GLUquadricObj mercury;
GLuint txtMercury;
BITMAPINFOHEADER bitmapInfoHeader;
unsigned char
bitmapData;

void display() {
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glBindTexture(GL_TEXTURE_2D,txtMercury);
gluSphere(mercury, 1.0, 32, 32);
glFlush();
}

void init(void) {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-4.0,4.0,-4.0,4.0,0.0,10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_TEXTURE_2D);
bitmapData = LoadBitmapFile(“Venus.bmp”,&bitmapInfoHeader);
glGenTextures(1,&txtMercury);
glBindTexture(GL_TEXTURE_2D,txtMercury);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,bitmapInfoHeader.biWidth,bitmapInfoHeader.biHeight,0,GL_RGB,GL_UNSIGNED_BYTE, bitmapData);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
mercury=gluNewQuadric();
gluQuadricTexture(mercury,GLU_TRUE);
gluQuadricDrawStyle(mercury,GLU_FILL);
gluQuadricNormals(mercury,GLU_SMOOTH);
free(bitmapData);
}

int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800,800);
glutInitWindowPosition(100,100);
glutCreateWindow(“20918381 Planets”);
init();
glutDisplayFunc(display);
glutMainLoop();
}

this is how it is now:

#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include “fileFunctions.h”

using namespace std;

GLfloat viewangle = 0, tippangle = 0;
GLfloat xAngle = 0.0, yAngle = 0.0, zAngle = 0.0;
GLfloat d[3] = {0.1, 0.1, 0.1};

float angle[6];

GLuint textureID[9];
GLUquadricObj *sun;
GLUquadricObj *mercury;
GLUquadricObj *venus;
GLUquadricObj *earth;
GLUquadricObj *earthmoon;
GLUquadricObj *mercurymoon;
GLUquadricObj *uranus;
GLUquadricObj *uranusmoon;
GLUquadricObj *bianca;

BITMAPINFOHEADER bitmapInfoHeader;
unsigned char* bitmapData;

void drawSun(){
glBindTexture(GL_TEXTURE_2D,textureID[0]);
glRotatef(angle[0],0.0,1,0.0);
gluSphere(sun, 1.0, 32, 32);
}
void drawMercury(){
glBindTexture(GL_TEXTURE_2D,textureID[1]);
glRotatef(angle[1],0.0,1,0.0);
gluSphere(mercury, 0.5, 32, 32);
}
void drawVenus(){

}
void drawEarth(){

}
void drawEarthMoon(){

}
void drawMercuryMoon(){

}
void drawUranus(){

}
void drawUranusMoon(){

}
void drawBianca(){

}

void rotate(){
angle[0]+=0.005;
if (angle[0]>360)angle[0]-=360;
angle[1]+= 0.05;
if (angle[1]>360) angle[1]-=360;
glutPostRedisplay();
}

void Special_Keys (int key, int x, int y)
{
switch (key) {
case GLUT_KEY_LEFT : viewangle -= 5; break;
case GLUT_KEY_RIGHT: viewangle += 5; break;
case GLUT_KEY_UP : tippangle -= 5; break;
case GLUT_KEY_DOWN : tippangle += 5; break;
}
glutPostRedisplay();
}
void keyPressed(unsigned char key, int x, int y){
switch (key) {
case ‘j’ : d[0] += 0.1; break;
case ‘k’ : d[1] += 0.1; break;
case ‘l’ : d[2] += 0.1; break;

   case 'x' : xAngle += 5;  break;
   case 'y' : yAngle += 5;  break;
   case 'z' : zAngle += 5;  break;
}
glutPostRedisplay();

}

void display() {
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable (GL_DEPTH_TEST);
glLoadIdentity();
gluLookAt(3.0,3.0,3.0, 0.0,0.0,0.0, 0.0,1,0.0);
glRotatef (tippangle, 1,0,0); // Up and down arrow keys ‘tip’ view.
glRotatef (viewangle, 0,1,0); // Right/left arrow keys ‘turn’ view.
GLfloat light_pos[] = {0.0,0.0,0.0, 1.0};
glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
GLfloat ambient[] = {1,1,1};
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glPushMatrix ();
glTranslatef (d[0], d[1], d[2]); // Move box down X axis.
drawSun();
glTranslatef(0.5,0.5,-2);
drawMercury();
glRotatef (zAngle, 0,0,1);
glRotatef (yAngle, 0,1,0);
glRotatef (xAngle, 1,0,0);
glPopMatrix ();
glFlush();
glutSwapBuffers();
}

void init(void) {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-4.0,4.0,-4.0,4.0,0.0,10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_TEXTURE_2D);
glGenTextures(9, textureID);

 for(int i=0;i&lt;9;i++) {
   glBindTexture(GL_TEXTURE_2D,textureID[i]);
   char imageName[50]={'\0'};
   sprintf(imageName, "image%d.bmp",i);
   unsigned char* bitmapData = LoadBitmapFile(imageName, &bitmapInfoHeader);
   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_CLAMP); 
   glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
   glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,bitmapInfoHeader.biWidth,bitmapInfoHeader.biHeight,0,GL_RGB,GL_UNSIGNED_BYTE, bitmapData);
   free(bitmapData);
   }

 sun=gluNewQuadric();
 mercury=gluNewQuadric();
 venus=gluNewQuadric();
 earth=gluNewQuadric();
 earthmoon=gluNewQuadric();
 mercurymoon=gluNewQuadric();
 uranus=gluNewQuadric();
 uranusmoon=gluNewQuadric();
 bianca=gluNewQuadric();
 
 gluQuadricTexture(sun,GLU_TRUE);
 gluQuadricDrawStyle(sun,GLU_FILL);
 gluQuadricNormals(sun,GLU_SMOOTH);
 gluQuadricTexture(mercury,GLU_TRUE);
 gluQuadricDrawStyle(mercury,GLU_FILL);
 gluQuadricNormals(mercury,GLU_SMOOTH);

}

int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800,800);
glutInitWindowPosition(100,100);
glutCreateWindow(“20918381 Planets”);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
angle[0]=0;
angle[1]=0;
glutIdleFunc(rotate);
glutKeyboardFunc(keyPressed);
glutSpecialFunc(Special_Keys);
init();
glutDisplayFunc(display);
glutMainLoop();
}

Hi,
I copied the whole code and it works fine. I see two sphere with textures. Just to make things clear I have three source files, fileFunctions.h containing just the declaration


//fileFunctions.h
unsigned char *LoadBitmapFile(char *filename, BITMAPINFOHEADER *bitmapInfoHeader);

fileFunctions.cpp contains the implementation of the func. as u gave earlier.


//fileFunctions.cpp
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include "fileFunctions.h"

// Returns a pointer to the bitmap image of the bitmap specified
// by filename. Also returns the bitmap header information.
// No support for 8-bit bitmaps.
unsigned char *LoadBitmapFile(char *filename, BITMAPINFOHEADER *bitmapInfoHeader)
{
FILE *filePtr;
BITMAPFILEHEADER bitmapFileHeader;
unsigned char *bitmapImage;
int imageIdx = 0;
unsigned char tempRGB;
filePtr = fopen(filename, "rb");
if (filePtr == NULL) return NULL;
fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr);
fread(bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, filePtr);
fseek(filePtr, bitmapFileHeader.bfOffBits, SEEK_SET);
bitmapImage = (unsigned char*)malloc(bitmapInfoHeader->biSizeImage);
fread(bitmapImage, 1, bitmapInfoHeader->biSizeImage, filePtr);
for (imageIdx = 0; imageIdx < bitmapInfoHeader->biSizeImage; imageIdx+=3)
{
tempRGB = bitmapImage[imageIdx];
bitmapImage[imageIdx] = bitmapImage[imageIdx + 2];
bitmapImage[imageIdx + 2] = tempRGB;

}
return bitmapImage;
}

}

and the main.cpp file


//main.cpp
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include "fileFunctions.h"


GLfloat viewangle = 0, tippangle = 0;
GLfloat xAngle = 0.0, yAngle = 0.0, zAngle = 0.0;
GLfloat d[3] = {0.1, 0.1, 0.1};

float angle[6];

GLuint textureID[9];
GLUquadricObj *sun;
GLUquadricObj *mercury;
GLUquadricObj *venus;
GLUquadricObj *earth;
GLUquadricObj *earthmoon;
GLUquadricObj *mercurymoon;
GLUquadricObj *uranus;
GLUquadricObj *uranusmoon;
GLUquadricObj *bianca;

BITMAPINFOHEADER bitmapInfoHeader;
unsigned char* bitmapData;

void drawSun(){
glBindTexture(GL_TEXTURE_2D,textureID[0]);
glRotatef(angle[0],0.0,1,0.0);
gluSphere(sun, 1.0, 32, 32);
}
void drawMercury(){
glBindTexture(GL_TEXTURE_2D,textureID[1]);
glRotatef(angle[1],0.0,1,0.0);
gluSphere(mercury, 0.5, 32, 32);
}
void drawVenus(){

}
void drawEarth(){

}
void drawEarthMoon(){

}
void drawMercuryMoon(){

}
void drawUranus(){

}
void drawUranusMoon(){

}
void drawBianca(){

}

void rotate(){
angle[0]+=0.005;
if (angle[0]>360)angle[0]-=360;
angle[1]+= 0.05;
if (angle[1]>360) angle[1]-=360;
glutPostRedisplay();
}

void Special_Keys (int key, int x, int y)
{
switch (key) {
case GLUT_KEY_LEFT : viewangle -= 5; break;
case GLUT_KEY_RIGHT: viewangle += 5; break;
case GLUT_KEY_UP : tippangle -= 5; break;
case GLUT_KEY_DOWN : tippangle += 5; break;
}
glutPostRedisplay();
}
void keyPressed(unsigned char key, int x, int y){
switch (key) {
case 'j' : d[0] += 0.1; break;
case 'k' : d[1] += 0.1; break;
case 'l' : d[2] += 0.1; break;

case 'x' : xAngle += 5; break;
case 'y' : yAngle += 5; break;
case 'z' : zAngle += 5; break;
}
glutPostRedisplay();
}

void display() {
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable (GL_DEPTH_TEST);
glLoadIdentity();
gluLookAt(3.0,3.0,3.0, 0.0,0.0,0.0, 0.0,1,0.0); 
glRotatef (tippangle, 1,0,0); // Up and down arrow keys 'tip' view.
glRotatef (viewangle, 0,1,0); // Right/left arrow keys 'turn' view.
GLfloat light_pos[] = {0.0,0.0,0.0, 1.0};
glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
GLfloat ambient[] = {1,1,1};
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); 
glPushMatrix ();
glTranslatef (d[0], d[1], d[2]); // Move box down X axis.
drawSun();
glTranslatef(0.5,0.5,-2);
drawMercury();
glRotatef (zAngle, 0,0,1);
glRotatef (yAngle, 0,1,0);
glRotatef (xAngle, 1,0,0);
glPopMatrix ();
glFlush();
glutSwapBuffers();
}

void init(void) {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-4.0,4.0,-4.0,4.0,0.0,10.0); 
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_TEXTURE_2D);
glGenTextures(9, textureID);

for(int i=0;i<9;i++) {
glBindTexture(GL_TEXTURE_2D,textureID[i]);
char imageName[50]={'\0'};
sprintf(imageName, "image%d.bmp",i);
unsigned char* bitmapData = LoadBitmapFile(imageName, &bitmapInfoHeader);
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_CLAMP); 
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,bitmapInfoHeader.biWidth,bitmapInfoHeader.biHeight,0,GL_RGB,GL_UNSIGNED_BYTE, bitmapData);
free(bitmapData);
}

sun=gluNewQuadric();
mercury=gluNewQuadric();
venus=gluNewQuadric();
earth=gluNewQuadric();
earthmoon=gluNewQuadric();
mercurymoon=gluNewQuadric();
uranus=gluNewQuadric();
uranusmoon=gluNewQuadric();
bianca=gluNewQuadric();

gluQuadricTexture(sun,GLU_TRUE);
gluQuadricDrawStyle(sun,GLU_FILL);
gluQuadricNormals(sun,GLU_SMOOTH);
gluQuadricTexture(mercury,GLU_TRUE);
gluQuadricDrawStyle(mercury,GLU_FILL);
gluQuadricNormals(mercury,GLU_SMOOTH);
}

int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800,800);
glutInitWindowPosition(100,100);
glutCreateWindow("20918381 Planets");
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
angle[0]=0;
angle[1]=0;
glutIdleFunc(rotate);
glutKeyboardFunc(keyPressed);
glutSpecialFunc(Special_Keys);
init();
glutDisplayFunc(display);
glutMainLoop();
}

Could u recheck that the images are in the proper folder?

they are in the project folder with my .cpp files