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.

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 );

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.

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.

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.

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.

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?

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

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

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.

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

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!

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 );
}
commented: Thank you, thank you thank you! +2

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!

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.