Texture Issues

This is very strange indeed. It works perfectly fine here. I have all the images, source files (main.cpp, fileFunctions.h/cpp) and the solution file .sln,.vcproj in the same folder. It works fine.

Were u able to see the textured spheres before? And u said earlier that

but now i get the quads and no materials

You are not getting spheres?

yes i was, then it all went wrong when we created the array when I had trouble loading more than one texture…

Can my header file load more than one image?

is there incorrect syntax in:
char imageName[50]={’\0’};
sprintf(imageName, “image%d.bmp”,i);
unsigned char* bitmapData = LoadBitmapFile(imageName, &bitmapInfoHeader);

Ive even ensured my output and build folders are the same as my project ones in DEV c++ as this can provide some issues, like I said earlier im not running it on VB

all I currently get a re two spheres with no textures

This is correct this function can be called any number of times and it will load the bmp correctly. nothing wrong with the code it works fine here. Are u certain that the bitmaps are 24bit bmp and not anyother bmp like compressed or 32 bit.

I have also checked my .bmp files, they are 24 bit and in a power of 2 format.

OK ignore me, i have just figures it out, my .bmp files were named image0.bmp.bmp lol, my bad during the renaming of my files

thanks for all your help you rock!!!

No problems :slight_smile: it happens with everyone.

Hey Mobeen,

Just need to pick your brains for a couple more issues. How do I rotate the planets in different directions around the sun, for example the earth clockwise yet mercury counter clockwise?

Also how can i apply a background onto my scene?

Just FYI here is my up to date code so far:

#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include “fileFunctions.h”
// Martin Whittington 20918381
using namespace std;
// My variables
GLfloat viewangle = 0;
static GLfloat zZoom =0;
float angle[6];
int axis=0;
// Setup my texture array, as I need to load more than one
GLuint textureID[9];
// create pointers for my planets
GLUquadricObj *sun;
GLUquadricObj *mercury;
GLUquadricObj *venus;
GLUquadricObj *earth;
GLUquadricObj *earthMoon;
GLUquadricObj *mercuryMoon;
GLUquadricObj *uranus;
GLUquadricObj *uranusMoon;
GLUquadricObj bianca;
// For enabling file reading and handling
BITMAPINFOHEADER bitmapInfoHeader;
unsigned char
bitmapData;

void drawSun(){
// draw my sun
glBindTexture(GL_TEXTURE_2D,textureID[0]);
glRotatef(angle[0],0.0,1.0,0.0);
gluSphere(sun,1.0,32,32);
}
void drawMercury(){
// draw Mercury
glBindTexture(GL_TEXTURE_2D,textureID[1]);
glRotatef(angle[1],0.0,1.0,0.0);
gluSphere(mercury,0.75,32,32);
}
void drawMercuryMoon(){
// Draw Mercurys moon
glBindTexture(GL_TEXTURE_2D,textureID[2]);
glRotatef(angle[2],0.0,1.0,0.0);
gluSphere(mercuryMoon,0.1,32,32);
}
void drawEarth(){
// Draw Earth
glBindTexture(GL_TEXTURE_2D,textureID[3]);
glRotatef(angle[1],0.0,1.0,0.0);
gluSphere(earth,0.5,32,32);
}
void drawUranus(){
// Draw Uranus LOL
glBindTexture(GL_TEXTURE_2D,textureID[4]);
gluSphere(uranus,0.75,32,32);
}
void drawEarthMoon(){
// Draw Earths Moon
glBindTexture(GL_TEXTURE_2D,textureID[5]);
gluSphere(earthMoon,0.1,32,32);
}
void drawBianca(){
// Draw Bianca
glBindTexture(GL_TEXTURE_2D,textureID[2]);
gluSphere(bianca,0.1,32,32);
}
void drawUranusMoon(){
// Draw 2nd Uranus Moon
glBindTexture(GL_TEXTURE_2D,textureID[5]);
gluSphere(uranusMoon,0.2,32,32);
}
void drawVenus(){
// Draw Venus
glBindTexture(GL_TEXTURE_2D,textureID[6]);
gluSphere(venus,0.75,32,32);
}

void rotate(){
// Here I setup up different rotation angles so I could vary the spinning speeds of my planets
angle[0]+=0.009;
if (angle[0]>360)angle[0]-=360;
angle[1]+=0.05;
if (angle[1]>360)angle[1]-=360;
angle[2]-=0.1;
if (angle[2]>360)angle[2]-=360;
angle[3]-=0.05;
if (angle[3]<360)angle[3]+=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_DOWN : zZoom -= 0.1; break;
case GLUT_KEY_UP : zZoom += 0.1; break;
}
glutPostRedisplay();
}

void display() {
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0,1.0,3.0,0.0,0.0,0.0,0.0,1.0,1.0);
glTranslatef(0,0,zZoom); // Up and down arrow keys ‘zoom’ 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[] = {2,2,2};
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glPushMatrix();
drawSun();
glPopMatrix();
glPushMatrix();
glTranslatef(0.5,0.5,-4);
drawMercury();
glTranslatef(0.5,0.0,-1.0);
drawMercuryMoon();
glPopMatrix();
glPushMatrix();
glTranslatef(-5,0.0,-8.0);
drawUranus();
glTranslatef(-0.2,0.0,1.2);
drawBianca();
glTranslatef(0.5,0.0,-3.5);
drawUranusMoon();
glPopMatrix();
glPushMatrix();
glTranslatef(-6.0,0.0,-2.0);
drawEarth();
glTranslatef(0.5,0.0,-1.0);
drawEarthMoon();
glPopMatrix();
glPushMatrix();
glTranslatef(2.0,0.0,5.0);
drawVenus();
glPopMatrix();
glFlush();
glutSwapBuffers();
}

void init(void) {
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0,1.0,-1.0,1.0,1.0,25.0);
glOrtho(4.0,4.0,4.0,4.0,0.0,10.0);
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);
 gluQuadricTexture(mercuryMoon,GLU_TRUE);
 gluQuadricDrawStyle(mercuryMoon,GLU_FILL);
 gluQuadricNormals(mercuryMoon,GLU_SMOOTH);
 gluQuadricTexture(earth,GLU_TRUE);
 gluQuadricDrawStyle(earth,GLU_FILL);
 gluQuadricNormals(earth,GLU_SMOOTH);
 gluQuadricTexture(uranus,GLU_TRUE);
 gluQuadricDrawStyle(uranus,GLU_FILL);
 gluQuadricNormals(uranus,GLU_SMOOTH);
 gluQuadricTexture(earthMoon,GLU_TRUE);
 gluQuadricDrawStyle(earthMoon,GLU_FILL);
 gluQuadricNormals(earthMoon,GLU_SMOOTH);
 gluQuadricTexture(bianca,GLU_TRUE);
 gluQuadricDrawStyle(bianca,GLU_FILL);
 gluQuadricNormals(bianca,GLU_SMOOTH);
 gluQuadricTexture(uranusMoon,GLU_TRUE);
 gluQuadricDrawStyle(uranusMoon,GLU_FILL);
 gluQuadricNormals(uranusMoon,GLU_SMOOTH);
 gluQuadricTexture(venus,GLU_TRUE);
 gluQuadricDrawStyle(venus,GLU_FILL);
 gluQuadricNormals(venus,GLU_SMOOTH);

}

int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(900,900);
glutInitWindowPosition(100,100);
glutCreateWindow(“20918381 Planets”);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
angle[0]=0;
angle[1]=0;
angle[2]=0;
angle[3]=0;
angle[4]=0;
angle[5]=0;
angle[6]=0;
glutIdleFunc(rotate);
glutSpecialFunc(Special_Keys);
init();
glutDisplayFunc(display);
glutMainLoop();
}
the header file and supporting .cpp file havent changed since the previous posts

thanks in advance

Martin