0

Hello. I've been messing around with applying textures and i managed to apply one with no hiccups. By subsequent attempts , however, keeps turning my spheres blue! I don't know what to do.

I'm attaching what i've done so far because it's kind of long. If anyone can help me i would really appreciate it.

Attachments
#include <gl/glut.h>
#include <math.h>
#include "stdlib.h"
#include "ctype.h"
#include <stdio.h>
#include <windows.h>

#define MAX_NO_TEXTURES 4

#define EARTH_TEXTURE   0
#define VENUS_TEXTURE   1
#define MERCURY_TEXTURE 2
#define MARS_TEXTURE 3


// Storage for texture names
GLuint  texture_id[MAX_NO_TEXTURES];


static float AngleM = 0.0;
static float AngleP = 0.0;
//camera rotation
float xpos = 0, ypos = 0, zpos = 0, xrot = 0, yrot = 0, angle=0.0;
bool rotate = true;

	// Lighting values
    GLfloat mat_specular[]={1.0, 1.0, 1.0, 1.0};
    GLfloat mat_diffuse[]={1.0, 1.0, 1.0, 1.0};
    GLfloat mat_ambient[]={1.0, 1.0, 1.0, 1.0};
    GLfloat mat_shininess={100.0};

    GLfloat ambientLight0[] = { 0.5f, 0.5f, 0.5f, 1.0f };
	GLfloat ambientLight1[] = { 0.1f, 0.1f, 0.1f, 1.0f };
    GLfloat diffuseLight[]={1.0, 1.0, 1.0, 1.0};
    GLfloat specularLight[]={0.0, 1.0, 0.0, 1.0};

	GLfloat light_position[] = { 0.0f, 0.0f, 0.0f, 1.0f };
	
	GLfloat specref[] = { 1.0f, 1.0f, 1.0f, 1.0f };
	GLfloat emissionSun[] = { 0.9f, 0.0f, 0.0f, 0.0f};
	
	GLfloat null[] = { 0.0f, 0.0f, 0.0f, 1.0f};
	


void DrawOrbit(GLfloat rad, GLfloat inc)
{
	glPushMatrix();

	GLfloat y = 0.0;
	glColor3f(0.5, 0.5, 0.5);

	glBegin(GL_POINTS);
	for(GLfloat angle = 0; angle <= 360; angle+=inc)
	{
		GLfloat x = rad*sin((angle)*3.1415926535/180);
		GLfloat z = rad*cos((angle)*3.1415926535/180);

		glVertex3f(x, y, z);
	}
	glEnd();

	glPopMatrix();
}

void camera() 
{
	glRotatef(yrot,0.0,1.0,0.0); //rotate our camera on the y-axis (up and down)
	glRotatef(xrot,1.0,0.0,0.0); //rotate our camera on the x-axis (left and right)
	glTranslatef(-xpos, -ypos, -zpos); //translate the screen to the position of our camera
}
void rotateSphere()
{
	/* Idle callback, rotate sphere 15 degrees about selected axis */
	if (rotate == true)
	{
		AngleM += 2.0;
		if(AngleM > 360.0)
			AngleM = AngleM - 360.0;
		AngleP += 0.1;
		if(AngleP > 360.0)
			AngleP = AngleP - 360.0;
		glutPostRedisplay();
	}
	else
		rotate = false;
}


void keyboard(unsigned char c, int x, int y)
{
	switch (tolower(c))
	{
	case 'w':
		xrot += 2;
		if (xrot >360) xrot -= 360;
		break;

	case's':
		xrot -= 2;
		if (xrot < -360) xrot += 360;
		break;

	case'i':
		float xrotrad, yrotrad;
		yrotrad = (yrot / 180 * 3.141592654f);
		xrotrad = (xrot / 180 * 3.141592654f); 
		xpos += float(sin(yrotrad)) ;
		zpos -= float(cos(yrotrad)) ;
		ypos -= float(sin(xrotrad)) ;
		break;

	case'o':
		xrotrad, yrotrad;
		yrotrad = (yrot / 180 * 3.141592654f);
		xrotrad = (xrot / 180 * 3.141592654f);
		xpos -= float(sin(yrotrad));
		zpos += float(cos(yrotrad)) ;
		ypos += float(sin(xrotrad));
		break;

	case'd':
		yrot += 2;
		if (yrot >360) yrot -= 360;
		break;

	case'a':
		yrot -= 2;
		if (yrot < -360)yrot += 360;
		break;

	case'r': //reset
		xpos = 0, ypos = 0, zpos = 0, xrot = 0, yrot = 0, angle=0.0;
		break;

	case 'f':
		glutFullScreen ( );
        break;

	case 'p':
		rotate = false;
		break;

	case 'u':
		rotate = true;
		break;

	case 27: //Esc
		exit(0);
		break;
	}
}

void load_texture ( char *filename, int width, int height, int depth, GLenum colour_type, GLenum filter_type )
{
   GLubyte *texture ;
   FILE *file;

   /*if ((file = fopen(filename, "earth"))==NULL )
   {
      printf ( "File Not Found : %s\n", filename );
      exit   ( 1 );
   }*/
	file = fopen( filename, "rb" );
    if ( file == NULL ) 
		printf("File not found: \n", filename);

   texture = (GLubyte *) malloc ( width * height * depth * ( sizeof(GLubyte)) );

   if (texture == NULL)
   {
      printf ( "Cannot allocate memory for texture\n" );
      fclose ( file);
      exit   ( 1 );
   }

   fread  ( texture , width * height * depth, 1 , file );
   fclose ( file);

   //  Set Filtering type
   glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter_type );
   glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter_type );

   //  Set Texture Evironment
   glTexEnvf ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

   //  Build Mipmaps
   gluBuild2DMipmaps ( GL_TEXTURE_2D, colour_type, width, height,
                       colour_type, GL_UNSIGNED_BYTE, texture );

   //  Free up the array
   free ( texture );
}

void Mercury(int tex_id)
{
	DrawOrbit(5.5, 1);

	glPushMatrix();
	glRotatef(AngleP*6, 0.0, 1.0, 0.0); //rotate for the planet
	glTranslatef(5.5, 0.0, 0.0);
	glColor3f(1.0, 1.0, 1.0);
	glEnable ( GL_TEXTURE_2D );
	glBindTexture ( GL_TEXTURE_2D, texture_id[tex_id] );
	GLUquadricObj* m = gluNewQuadric (  );
    gluQuadricDrawStyle ( m, GLU_FILL   );
    gluQuadricNormals   ( m, GLU_SMOOTH );
	gluQuadricTexture   ( m, GL_TRUE    );
	gluSphere(m, 0.2, 10, 8); //draw planet
	gluDeleteQuadric ( m );
	glDisable ( GL_TEXTURE_2D );
	glPopMatrix();

}

void Venus(int tex_id)
{
	DrawOrbit(8.5, 1);

	glPushMatrix();
	glRotatef(AngleP*5, 0.0, 1.0, 0.0); //rotate for the planet
	glTranslatef(8.5, 0.0, 0.0);
	glColor3f(1.0, 1.0, 1.0);
	glEnable ( GL_TEXTURE_2D );
	glBindTexture ( GL_TEXTURE_2D, texture_id[tex_id] );
	GLUquadricObj* v = gluNewQuadric (  );
    gluQuadricDrawStyle ( v, GLU_FILL   );
    gluQuadricNormals   ( v, GLU_SMOOTH );
	gluQuadricTexture   ( v, GL_TRUE    );
	gluSphere(v, 0.35, 20, 16); //draw planet
	gluDeleteQuadric ( v );
	glDisable ( GL_TEXTURE_2D );
	glPopMatrix();


}

void Earth(int tex_id)
{
	DrawOrbit(10.5, 1);
	
	glPushMatrix();
	glRotatef(AngleP*3, 0.0, 1.0, 0.0); //rotate for the planet
	glTranslatef(10.5, 0.0, 0.0);
	glColor3f(1.0, 1.0, 1.0);
	glEnable ( GL_TEXTURE_2D );
	glBindTexture ( GL_TEXTURE_2D, texture_id[tex_id] );
	GLUquadricObj* q = gluNewQuadric (  );
    gluQuadricDrawStyle ( q, GLU_FILL   );
    gluQuadricNormals   ( q, GLU_SMOOTH );
	gluQuadricTexture   ( q, GL_TRUE    );
	gluSphere(q, 0.4, 20, 16); //draw planet
	gluDeleteQuadric ( q );
	glDisable ( GL_TEXTURE_2D );

	glRotatef(AngleM*2, 0.0, 1.0, 0.0); //rotate for the moon
	glTranslatef(0.6, 0.0, 0.0);
	glColor3f(0.5, 0.5, 0.5);
	glutSolidSphere(0.1, 5, 4); //draw moon
	glPopMatrix();

}

void Mars(int tex_id)
{
	DrawOrbit(16.5, .5);

	glRotatef(AngleP*2, 0.0, 1.0, 0.0); //rotate for the planet
	glTranslatef(16.5, 0.0, 0.0);
	glColor3f(1.0, 1.0, 1.0);
	glEnable ( GL_TEXTURE_2D );
	glBindTexture ( GL_TEXTURE_2D, texture_id[tex_id] );
	GLUquadricObj* M = gluNewQuadric (  );
    gluQuadricDrawStyle ( M, GLU_FILL   );
    gluQuadricNormals   ( M, GLU_SMOOTH );
	gluQuadricTexture   ( M, GL_TRUE    );
	gluSphere(M, 0.3, 20, 16); //draw planet
	gluDeleteQuadric ( M );
	glDisable ( GL_TEXTURE_2D );

	glPushMatrix();
	glRotatef(AngleM*3, 0.0, 1.0, 0.0); //rotate for the moon
	glTranslatef(0.7, 0.0, 0.0);
	glColor3f(0.5, 0.3, 0.0);
	glutSolidSphere(0.15, 5, 4); //draw moon

	glPopMatrix();
	glPushMatrix();
	glRotatef(AngleM*2, 0.0, 1.0, 0.0); //rotate for the moon
	glTranslatef(0.7, 0.0, 0.0);
	glColor3f(0.5, 0.3, 0.0);
	glutSolidSphere(0.15, 5, 4); //draw moon

	glPopMatrix();

}

void Jupiter(void)
{
	DrawOrbit(20.5, .3);

	glRotatef(AngleP*1.5, 0.0, 1.0, 0.0); //rotate for the planet
	glTranslatef(20.5, 0.0, 0.0);
	glColor3f(0.9, 0.9, 0.9);
	glutSolidSphere(0.8, 20, 16); //draw planet

	glPushMatrix();
	glRotatef(15.0, 0.0, 0.0, 1.0);
	glRotatef(AngleM*1.5, 0.0, 1.0, 0.0); //rotate for the moon
	glTranslatef(1.2, 0.0, 0.0);
	glColor3f(0.5, 0.3, 0.1);
	glutSolidSphere(0.1, 5, 4); //draw moon
	glPopMatrix();
	
	glPushMatrix();
	glRotatef(15.0, 0.0, 0.0, 1.0);
	glRotatef(AngleM*2, 0.0, 1.0, 0.0); //rotate for the moon
	glTranslatef(1.2, 0.0, 0.0);
	glColor3f(0.5, 0.3, 0.1);
	glutSolidSphere(0.1, 5, 4); //draw moon
	glPopMatrix();

	glPushMatrix();
	glRotatef(15.0, 0.0, 0.0, 1.0);
	glRotatef(AngleM, 0.0, 1.0, 0.0); //rotate for the moon
	glTranslatef(1.2, 0.0, 0.0);
	glColor3f(0.5, 0.3, 0.1);
	glutSolidSphere(0.1, 5, 4); //draw moon
	glPopMatrix();
	
	glPushMatrix();
	glRotatef(15.0, 0.0, 0.0, 1.0);
	glRotatef(AngleM*3, 0.0, 1.0, 0.0); //rotate for the moon
	glTranslatef(1.2, 0.0, 0.0);
	glColor3f(0.5, 0.3, 0.1);
	glutSolidSphere(0.1, 5, 4); //draw moon
	glPopMatrix();
}
void Saturn(void)
{
	DrawOrbit(25.0, .2);

	glRotatef(AngleP, 0.0, 1.0, 0.0); //rotate for the planet
	glTranslatef(25.0, 0.0, 0.0);
	glColor3f(0.0, 1.0, 0.9);
	glutSolidSphere(0.75, 20, 16); //draw planet

	glPushMatrix();
	glRotatef(15.0, 0.0, 0.0, 1.0);
	glRotatef(AngleM*1.5, 0.0, 1.0, 0.0); //rotate for the moon
	glTranslatef(1.2, 0.0, 0.0);
	glColor3f(0.5, 0.3, 0.1);
	glutSolidSphere(0.1, 5, 4); //draw moon
	glPopMatrix();
	
	glPushMatrix();
	glRotatef(15.0, 0.0, 0.0, 1.0);
	glRotatef(AngleM*2, 0.0, 1.0, 0.0); //rotate for the moon
	glTranslatef(1.2, 0.0, 0.0);
	glColor3f(0.5, 0.3, 0.1);
	glutSolidSphere(0.1, 5, 4); //draw moon
	glPopMatrix();

	glPushMatrix();
	glRotatef(15.0, 0.0, 0.0, 1.0);
	glRotatef(AngleM, 0.0, 1.0, 0.0); //rotate for the moon
	glTranslatef(1.2, 0.0, 0.0);
	glColor3f(0.5, 0.3, 0.1);
	glutSolidSphere(0.1, 5, 4); //draw moon
	glPopMatrix();
	
	glPushMatrix();
	glRotatef(15.0, 0.0, 0.0, 1.0);
	glRotatef(AngleM*3, 0.0, 1.0, 0.0); //rotate for the moon
	glTranslatef(1.2, 0.0, 0.0);
	glColor3f(0.5, 0.3, 0.1);
	glutSolidSphere(0.1, 5, 4); //draw moon
	glPopMatrix();
}

void display(void)
{
	////Add ambient light
	GLfloat global_ambient[]= {0.7f, 0.7f, 0.7f, 1.0f};
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);

	rotateSphere();

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	

	//position camera
	glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
	glTranslatef ( 0.0, 0.0, 4.0 );
	//gluOrtho2D(0.0f, 0.0f, 0.0f, 1.0f);
	//glOrtho(1.f, 1.f, 1.f, 1.f, 1.f, -5.f);
	gluLookAt (0.0, 0.0, 5.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0);
	//glFrustum (-1.0, 1.0, 0.0, 0.0, 1.5, -1.0);

	camera();

	//enable light 0
	glEnable(GL_LIGHT0);
	

	//set specular reflectivity with low shine
	glColor4f(1.0, 0.8, 0.0, 1.0);

	glMaterialfv(GL_FRONT, GL_SPECULAR, specref);
	glMateriali(GL_FRONT,
2
Contributors
14
Replies
16
Views
8 Years
Discussion Span
Last Post by wildgoose
Featured Replies
  • Okay looked at your BMP loader and noticed a big problem. I went into one of my full blown BMP loaders and twiddled yours specific to 24-bit RGB bitmaps. Problem #1 - you were treating header data as pixel data! Problem #2 - BGR vs RGB Problem #3 - You … Read More

0

You may want to mention it is OpenGL.
I cut in my own textures and Kind of cool, but I only see one blue planet.

Adding your textures would be cool. If you're worried about copy cats, Put a big X or something on your textures so that they still look about right, though contaminated with debris!


In my code I typically have the following Render...

cgGLSetTextureParameter( cg_BlinnTexture, iTex );

  cgGLEnableTextureParameter( cg_BlinnTexture );
  glEnable( GL_TEXTURE_2D );
  glBindTexture(GL_TEXTURE_2D, iTex);

  glEnableClientState( GL_TEXTURE_COORD_ARRAY );
  glTexCoordPointer( 2, GL_FLOAT, 0, pUVAry );		

  // other vertex information then draw

  glDisableClientState( GL_TEXTURE_COORD_ARRAY );

  glBindTexture(GL_TEXTURE_2D, 0);    // not necessary but I include it anyway!
  gllDisable( GL_TEXTURE_2D );

  cgGLDisableTextureParameter( cg_BlinnTexture );
0

Hey wildgoose! Thanks for replying. I did forget to say it was in opengl but you were smart enough to realize that it was =). I can upload the textures..its no big deal. They aren't personally made so i don't care. The only planet that should be remotely blue is the last one in the outer ring. The ones with the textures are orginallt colored white but when i apply the textures, they turn blue for some weird reason. Your render code looks similiar to mines minus a few different function calls.

0

Big possible problem.\
Your textures are not 2^N, and not all square.
Some video cards require square, but most definitely 2^N, with few exceptions. Try stretching the bitmap to 128x128, etc.

0

Yes your right! Theres something definately wrong with the pictures here. I tried mapping the earth texture to another planet and it turned out ok. I' just tried changing the aspect ratio to what you recommended but that doesn't seem to be fixing the problem. I'll need to tinker with this in the morning or maybe get a different picture or resize it using a different program.

0

I'm using images that adhere to that 2^N rule but am still getting the same problem. I do not believe this to be a power-of-2 issue or problem loading a texture that is beyond what my opengl implementation can do. I've also tried converting the images to .raw format to see if that changed anything but i just ended up with image distortions and you literally can't make anything out.

0

I can't examine your code right now, but have you tried increasing your radius to 4.0 or so, stopped the orbits, and rotated in place to see your planets better?

0

I can't examine your code right now, but have you tried increasing your radius to 4.0 or so, stopped the orbits, and rotated in place to see your planets better?

Have i tried inceasing what radius to 4.0?

I normally don't use the glQuad stuff. I use my own meshes, even for sphere's.

I am not that good with opengl so i like to use and tinker with already built in functions

0

The planets. They're pretty small to make out on screen and making them larger for testing purposes, and making them stationary infront of the viewport.

0

Ok i just did everything you just said to do and nothings really changed. This is so wierd, i don't know what the problem is. Earth is mapped out fine!

I'm about to upload an update of the code

Attachments
#include "gl\glut.h"
#include <math.h>
#include "stdlib.h"
#include "ctype.h"
#include <stdio.h>
#include <windows.h>

#define MAX_NO_TEXTURES 5

#define EARTH_TEXTURE   0
#define VENUS_TEXTURE   1
#define MERCURY_TEXTURE 2
#define MARS_TEXTURE 3
#define MOON_TEXTURE 4


// Storage for texture names
GLuint  texture_id[MAX_NO_TEXTURES];


static float AngleM = 0.0;
static float AngleP = 0.0;

//camera rotation
float xpos = 0, ypos = 0, zpos = 0, xrot = 0, yrot = 0, angle=0.0;
bool rotate = true;

	// Lighting values
    GLfloat mat_specular[]={1.0, 1.0, 1.0, 1.0};
    GLfloat mat_diffuse[]={1.0, 1.0, 1.0, 1.0};
    GLfloat mat_ambient[]={1.0, 1.0, 1.0, 1.0};
    GLfloat mat_shininess={100.0};

    GLfloat ambientLight0[] = { 0.5f, 0.5f, 0.5f, 1.0f };
	GLfloat ambientLight1[] = { 0.1f, 0.1f, 0.1f, 1.0f };
    GLfloat diffuseLight[]={1.0, 1.0, 1.0, 1.0};
    GLfloat specularLight[]={0.0, 1.0, 0.0, 1.0};

	GLfloat light_position[] = { 0.0f, 0.0f, 0.0f, 1.0f };
	
	GLfloat specref[] = { 1.0f, 1.0f, 1.0f, 1.0f };
	GLfloat emissionSun[] = { 0.9f, 0.0f, 0.0f, 0.0f};
	
	GLfloat null[] = { 0.0f, 0.0f, 0.0f, 1.0f};
	


void DrawOrbit(GLfloat rad, GLfloat inc)
{
	glPushMatrix();

	GLfloat y = 0.0;
	glColor3f(0.5, 0.5, 0.5);

	glBegin(GL_POINTS);
	for(GLfloat angle = 0; angle <= 360; angle+=inc)
	{
		GLfloat x = rad*sin((angle)*3.1415926535/180);
		GLfloat z = rad*cos((angle)*3.1415926535/180);

		glVertex3f(x, y, z);
	}
	glEnd();

	glPopMatrix();
}

void camera() 
{

	glRotatef(yrot,0.0,1.0,0.0); //rotate our camera on the y-axis (up and down)
	glTranslatef(-xpos, -ypos, -zpos); //translate the screen to the position of our camera
	glRotatef(xrot,1.0,0.0,0.0); //rotate our camera on the x-axis (left and right)
	
}
void rotateSphere()
{
	// Idle callback, rotate sphere 15 degrees about selected axis 
	if (rotate == true)
	{
		AngleM += 2.0;
		//if(AngleM > 360.0)
			//AngleM = AngleM - 360.0;
		AngleP += 0.1;
		//if(AngleP > 360.0)
			//AngleP = AngleP - 360.0;
		glRotatef(AngleP*6, 0.0, 1.0, 0.0);
		glutPostRedisplay();
	}
	else
		rotate = false;
}


void keyboard(unsigned char c, int x, int y)
{
	switch (tolower(c))
	{
	case 'w':
		xrot += 2;
		if (xrot >360) xrot -= 360;
		break;

	case's':
		xrot -= 2;
		if (xrot < -360) xrot += 360;
		break;

	case'i':
		float xrotrad, yrotrad;
		yrotrad = (yrot / 180 * 3.141592654f);
		xrotrad = (xrot / 180 * 3.141592654f); 
		xpos += float(sin(yrotrad)) ;
		zpos -= float(cos(yrotrad)) ;
		ypos -= float(sin(xrotrad)) ;
		break;

	case'o':
		xrotrad, yrotrad;
		yrotrad = (yrot / 180 * 3.141592654f);
		xrotrad = (xrot / 180 * 3.141592654f);
		xpos -= float(sin(yrotrad));
		zpos += float(cos(yrotrad)) ;
		ypos += float(sin(xrotrad));
		break;

	case'd':
		yrot += 2;
		if (yrot >360) yrot -= 360;
		break;

	case'a':
		yrot -= 2;
		if (yrot < -360)yrot += 360;
		break;
	case 'z':
		xpos +=1;
		break;
	case 'x':
		xpos-=1;
		break;

	case'r': //reset
		xpos = 0, ypos = 0, zpos = 0, xrot = 0, yrot = 0, angle=0.0;
		break;

	case 'f':
		glutFullScreen ( );
        break;

	case 'p':
		rotate = false;
		break;

	case 'u':
		rotate = true;
		glutPostRedisplay();
		break;

	case 27: //Esc
		exit(0);
		break;
	}
}

void load_texture ( char *filename, int width, int height, int depth, GLenum colour_type, GLenum filter_type )
{
   GLubyte *texture ;
   FILE *file;

   /*if ((file = fopen(filename, "rb"))==NULL )
   {
      printf ( "File Not Found : %s\n", filename );
      exit   ( 1 );
   }*/
	file = fopen( filename, "rb" );
    if ( file == NULL ) 
		printf("File not found: \n", filename);

   texture = (GLubyte *) malloc ( width * height * depth * ( sizeof(GLubyte)) );

   if (texture == NULL)
   {
      printf ( "Cannot allocate memory for texture\n" );
      fclose ( file);
      exit   ( 1 );
   }

   fread  ( texture , width * height * depth, 1 , file );
   fclose ( file);

   //  Set Filtering type
   glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter_type );
   glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter_type );

   //  Set Texture Evironment
   glTexEnvf ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

   //  Build Mipmaps
   gluBuild2DMipmaps ( GL_TEXTURE_2D, colour_type, width, height,
                       colour_type, GL_UNSIGNED_BYTE, texture );

   //  Free up the array
   free ( texture );
}

void Mercury(int tex_id)
{
	DrawOrbit(6.5, 1);
	glPushMatrix();
	glRotatef(AngleP*6, 0.0, 1.0, 0.0); //rotate on y for the planet
	glRotatef(AngleP*6, 1.0, 0.0, 0.0); //rotate on x for the planet
	glTranslatef(6.5, 0.0, 0.0);
	glColor3f(1.0, 1.0, 1.0);
	glEnable ( GL_TEXTURE_2D );
	glBindTexture ( GL_TEXTURE_2D, texture_id[tex_id] );
	GLUquadricObj* m = gluNewQuadric (  );
    gluQuadricDrawStyle ( m, GLU_FILL   );
    gluQuadricNormals   ( m, GLU_SMOOTH );
	gluQuadricTexture   ( m, GL_TRUE    );
	gluSphere(m, 1.0, 10, 8); //draw planet
	gluDeleteQuadric ( m );
	glDisable ( GL_TEXTURE_2D );
	glPopMatrix();

}

void Venus(int tex_id)
{
	DrawOrbit(9.5, 1);

	glPushMatrix();
	glRotatef(AngleP*5, 0.0, 1.0, 0.0); //rotate on y for the planet
	glRotatef(AngleP*5, 1.0, 0.0, 0.0); //rotate on x for the planet
	glTranslatef(9.5, 0.0, 0.0);
	glColor3f(1.0, 1.0, 1.0);
	glEnable ( GL_TEXTURE_2D );
	glBindTexture ( GL_TEXTURE_2D, texture_id[tex_id] );
	GLUquadricObj* v = gluNewQuadric (  );
    gluQuadricDrawStyle ( v, GLU_FILL   );
    gluQuadricNormals   ( v, GLU_SMOOTH );
	gluQuadricTexture   ( v, GL_TRUE    );
	gluSphere(v, 1.15, 20, 16); //draw planet
	gluDeleteQuadric ( v );
	glDisable ( GL_TEXTURE_2D );
	glPopMatrix();


}

void Earth(int tex_id)
{
	DrawOrbit(14.5, 1);
	
	glPushMatrix();
	glRotatef(AngleP*3, 0.0, 1.0, 0.0); //rotate on y for the planet
	glRotatef(AngleP*3, 1.0, 0.0, 0.0); //rotate on x for the planet
	glTranslatef(14.5, 0.0, 0.0);
	glColor3f(1.0, 1.0, 1.0);
	glEnable ( GL_TEXTURE_2D );
	glBindTexture ( GL_TEXTURE_2D, texture_id[tex_id] );
	GLUquadricObj* q = gluNewQuadric (  );
    gluQuadricDrawStyle ( q, GLU_FILL   );
    gluQuadricNormals   ( q, GLU_SMOOTH );
	gluQuadricTexture   ( q, GL_TRUE    );
	gluSphere(q, 1.4, 20, 16); //draw planet
	gluDeleteQuadric ( q );
	glDisable ( GL_TEXTURE_2D );
	//glPopMatrix();
}
void Earths_Moon( int tex_id)
{
	glRotatef(AngleM*1, 0.0, 1.0, 0.0); //rotate for the moon
	glTranslatef(1.5, 0.0, 0.0);
	glColor3f(0.5, 0.5, 0.5);
	glEnable ( GL_TEXTURE_2D );
	glBindTexture ( GL_TEXTURE_2D, texture_id[tex_id] );
	GLUquadricObj* moon = gluNewQuadric (  );
    gluQuadricDrawStyle ( moon, GLU_FILL   );
    gluQuadricNormals   ( moon, GLU_SMOOTH );
	gluQuadricTexture   ( moon, GL_TRUE    );
	gluSphere(moon, 0.3, 10, 6); //draw moon
	gluDeleteQuadric ( moon );
	glDisable ( GL_TEXTURE_2D );
	glPopMatrix();
}


void Mars(int tex_id)
{
	DrawOrbit(18.5, .5);

	glRotatef(AngleP*2, 0.0, 1.0, 0.0); //rotate on y for the planet
	glRotatef(AngleP*2, 1.0, 0.0, 0.0); //rotate on x for the planet
	glTranslatef(18.5, 0.0, 0.0);
	glColor3f(1.0, 1.0, 1.0);
	glEnable ( GL_TEXTURE_2D );
	glBindTexture ( GL_TEXTURE_2D, texture_id[tex_id] );
	GLUquadricObj* M = gluNewQuadric (  );
    gluQuadricDrawStyle ( M, GLU_FILL   );
    gluQuadricNormals   ( M, GLU_SMOOTH );
	gluQuadricTexture   ( M, GL_TRUE    );
	gluSphere(M, 1.12, 20, 16); //draw planet
	gluDeleteQuadric ( M );
	glDisable ( GL_TEXTURE_2D );

	glPushMatrix();
	glRotatef(AngleM*2, 0.0, 1.0, 0.0); //rotate for the moon
	glTranslatef(1.5, 0.0, 0.0);
	glColor3f(0.5, 0.3, 0.0);
	glutSolidSphere(0.3, 10, 6); //draw moon

	glPopMatrix();
	glPushMatrix();
	glRotatef(AngleM*1, 0.0, 1.0, 0.0); //rotate for the moon
	glTranslatef(1.5, 0.0, 0.0);
	glColor3f(0.5, 0.3, 0.0);
	glutSolidSphere(0.3, 10, 6); //draw moon

	glPopMatrix();

}

void Jupiter(void)
{
	DrawOrbit(22.5, .3);

	glRotatef(AngleP*1.5, 0.0, 1.0, 0.0); //rotate on y for the planet
	glRotatef(AngleP*1.5, 1.0, 0.0, 0.0); //rotate on x for the planet
	glTranslatef(20.5, 0.0, 0.0);
	glColor3f(0.9, 0.9, 0.9);
	glutSolidSphere(0.8, 20, 16); //draw planet

	glPushMatrix();
	glRotatef(15.0, 0.0, 0.0, 1.0);
	glRotatef(AngleM*1.5, 0.0, 1.0, 0.0); //rotate for the moon
	glTranslatef(1.2, 0.0, 0.0);
	glColor3f(0.5, 0.3, 0.1);
	glutSolidSphere(0.1, 5, 4); //draw moon
	glPopMatrix();
	
	glPushMatrix();
	glRotatef(15.0, 0.0, 0.0, 1.0);
	glRotatef(AngleM*2, 0.0, 1.0, 0.0); //rotate for the moon
	glTranslatef(1.2, 0.0, 0.0);
	glColor3f(0.5, 0.3, 0.1);
	glutSolidSphere(0.1, 5, 4); //draw moon
	glPopMatrix();

	glPushMatrix();
	glRotatef(15.0, 0.0, 0.0, 1.0);
	glRotatef(AngleM, 0.0, 1.0, 0.0); //rotate for the moon
	glTranslatef(1.2, 0.0, 0.0);
	glColor3f(0.5, 0.3, 0.1);
	glutSolidSphere(0.1, 5, 4); //draw moon
	glPopMatrix();
	
	glPushMatrix();
	glRotatef(15.0, 0.0, 0.0, 1.0);
	glRotatef(AngleM*3, 0.0, 1.0, 0.0); //rotate for the moon
	glTranslatef(1.2, 0.0, 0.0);
	glColor3f(0.5, 0.3, 0.1);
	glutSolidSphere(0.1, 5, 4); //draw moon
	glPopMatrix();
}
void Saturn(void)
{
	DrawOrbit(27.0, .2);
	
	glRotatef(AngleP, 0.0, 1.0, 0.0); //rotate on y for the planet
	glRotatef(AngleP, 1.0, 0.0, 0.0); //rotate on x for the planet
	glTranslatef(25.0, 0.0, 0.0);
	glColor3f(0.0, 1.0, 0.9);
	GLUquadricObj* S = gluNewQuadric (  );
	glutSolidSphere(0.75, 20, 16); //draw planet
	glColor3f(0.0, 0.0, 1.0);
	gluDisk (S, 1.5, 2.5, 500, 3);

	glPushMatrix();
	glRotatef(15.0, 0.0, 0.0, 1.0);
	glRotatef(AngleM*1.5, 0.0, 1.0, 0.0); //rotate for the moon
	glTranslatef(1.2, 0.0, 0.0);
	glColor3f(0.5, 0.3, 0.1);
	glutSolidSphere(0.1, 5, 4); //draw moon
	glPopMatrix();
	
	glPushMatrix();
	glRotatef(15.0, 0.0, 0.0, 1.0);
	glRotatef(AngleM*2, 0.0, 1.0, 0.0); //rotate for the moon
	glTranslatef(1.2, 0.0, 0.0);
	glColor3f(0.5, 0.3, 0.1);
	glutSolidSphere(0.1, 5, 4); //draw moon
	glPopMatrix();

	glPushMatrix();
	glRotatef(15.0, 0.0, 0.0, 1.0);
	glRotatef(AngleM, 0.0, 1.0, 0.0); //rotate for the moon
	glTranslatef(1.2, 0.0, 0
0

Your palette is flipped!

Red is Blue and Blue is Red. Green is fine!

You're using a 24-bit BMP and those are oriented Blue, Green, Red, however the frame buffer is Red, Green, Blue!

I usually use TGA's so I'm not sure if you need to swap the texture or if Glut is suppose to do it!

1

Okay looked at your BMP loader and noticed a big problem. I went into one of my full blown BMP loaders and twiddled yours specific to 24-bit RGB bitmaps.

Problem #1 - you were treating header data as pixel data!
Problem #2 - BGR vs RGB
Problem #3 - You had to hardcode your bitmap resolution instead of using the values set int the bitmap.

This is more like a hack but it'll fix your bitmap issue!

Note that I left your width, height, and depth to be passed in to the function but I actually ignore them as they are read from the file itself!

//
//	BMP version 3.x header
//

#pragma	pack(1)
typedef struct Bmp3XHead_Type
{
	unsigned short	ImageFileType;			// File Identifier (always 0)

	unsigned int	FileSize;				// Size of files in bytes
	unsigned short	Reserved[2];
	unsigned int	ImageDataOffset;			// Start of image data offset
} Bmp3XHead;
#pragma pack()



//
//	BMP version 3.x informational header
//

#pragma	pack(1)
typedef struct Bmp3XInfo_Type
{
	unsigned int	HeaderSize;		// Size of this header
	unsigned int	Width;			// Width of image
	unsigned int	Height;			// Height of bitmap in scanlines
	unsigned short	Planes;			// # of color planes
	unsigned short	Depth;			// # of bits per pixel
	unsigned int	Compression;		// Type of compression
	unsigned int	ImageSize;		// Size of bitmap in bytes
	unsigned int	HRes;			// Horizontal Resolution in pixels/meter
	unsigned int	VRes;			// Vertical Resolution in pixels/meter
	unsigned int	nColor;			// # of colors in image
	unsigned int	nColorCnt;		// Number of important colors in palette
} Bmp3XInfo;
#pragma pack()





void load_texture ( char *filename, int width, int height, int depth, GLenum colour_type, GLenum filter_type )
{
   GLubyte *texture ;
   FILE *file;

	file = fopen( filename, "rb" );
    if ( file == NULL ) 
		printf("File not found: \n", filename);

	Bmp3XHead head;

	fread( &head, sizeof(head), 1, file );
	if ( 0x4d42 != head.ImageFileType )
	{
		fclose(file);
		return;
	}

	Bmp3XInfo info;

	fread( &info, sizeof(info), 1, file );

	width = info.Width;
	height = info.Height;
	depth = info.Depth;

	if (depth != 24)
	{
		fclose( file );
		return;
	}

	depth >>= 3;

	fseek( file, head.ImageDataOffset, SEEK_SET );	// Start of pixels!

   texture = (GLubyte *) malloc ( width * height * depth * ( sizeof(GLubyte)) );

   if (texture == NULL)
   {
      printf ( "Cannot allocate memory for texture\n" );
      fclose ( file);
      exit   ( 1 );
   }

   fread  ( texture , width * height * depth, 1 , file );
   fclose ( file);

	// Swap blue & red
   GLubyte *pix, *pixEnd, col;
	pix = texture;
	pixEnd = texture + width * height * depth;

	while( pix < pixEnd )
	{
		col = *pix;
		*pix = *(pix+2);
		*(pix+2) = col;
		pix += 3;
	}

   //  Set Filtering type
   glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter_type );
   glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter_type );

   //  Set Texture Evironment
   glTexEnvf ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

   //  Build Mipmaps
   gluBuild2DMipmaps ( GL_TEXTURE_2D, colour_type, width, height,
                       colour_type, GL_UNSIGNED_BYTE, texture );

   //  Free up the array
   free ( texture );
}
Votes + Comments
Thank you, thank you thank you!
0

Mad respect wildgoose. I talked to my professor last night about my issue and we were on to what you managed to figure out. The problem definately lied with the images, more specifically the color indexes. When it stopped being an issue for me was when i decided not to use images in bmp format but rather use raw images. I mentioned I initially had an issue with images in said format and that was because the program i was using to convert my images was not doing it properly. I decided to use photoshop, and i should have done that in the first place, and i had working textures.

I'll definately try out the great fix, genius material btw, you posted for me when i get back from work and see how that turns out. Thanks a lot for analyzing my issue and helping me fix it!

+1!

0

no problem, just send the check to............

When I looked at it late last night I noticed again that the image seemed inverted blue vs brown. I scaled mars large, and when I applied the earth texture onto mars, water was brown, ground was blue. Then applied the moon texture onto mars, it appeared correct. That was clue #1 & 2.

I created a solid red texture and it showed up blue. I knew what was wrong but then tested the blue texture and it showed up red confirming my suspicion. And of course green was green. Thus the first posting of red and blue were swapped. I don't use BMP's I use TGA's but I remembered the BMP's are in BGR order, not RGB.

I then wrote the red-Blue color swapper and it didn't work. That's when I looked at your BMP loader more closely and then noticed the other problem. NO HEADERS. You were trying to treat the BMP like a raw file. I cut in the headers, overrode your inputs {w, h, d} with those from the file, and it came up like it was suppose to!

By the way. Move the image types within the planet functions themselves, don't keep them outside. And unless you're planning on trying to show earth textures on Jupiter, etc. Don't pass in the texture enum to get the texture name. Hard code them within the individual planet function's texture name lookup.

There are other cleanup issues, but just think, "How can I make this look more clean!" Once functionality is working. Save a copy of the project, then continue making changes. Archiving the project has to do with having a backup if cleaning goes terrible wrong. You'll have a fall back point to the last know good working version.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.