Original Post
I created a project based on Lesson 9 from Nehe in c# to load a ordered list of bitmaps and display them as an animation on Ortho mode. This works great so I decided I would move the project to C++. This also SEEMS to work fine except one problem, loading the same exact bitmaps the C# version of the application draws the bitmaps as they should be while the C++ project seems to draw them at a lower resolution. Both of the load routines come straight from the tutorials. C#: C++: Is there something else which may be causing it? The images are 512x512 (71dpi) created with Gimp 2.0. The application runs full screen with a 16 bit depth. I tried changing this to 32 but this did not help. Thanks kvn [edit: added source tags to reduce chaos. /Yann] [Edited by - Yann L on December 27, 2004 3:37:38 PM]
protected bool LoadTexture( string filename, uint[] htexture, int txtrindex )
{
Bitmap image = null;
try
{
image = new Bitmap(filename);
}
catch (System.ArgumentException)
{
MessageBox.Show("Could not load " + filename + ". Please make sure that Data is a subfolder from where the application is running.", "Error", MessageBoxButtons.OK);
this.finished = true;
return false;
}
if (image != null)
{
image.RotateFlip(RotateFlipType.RotateNoneFlipXY);
System.Drawing.Imaging.BitmapData bitmapdata;
Rectangle rect = new Rectangle(0, 0, image.Width, image.Height);
bitmapdata = image.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
GL.glBindTexture(GL.GL_TEXTURE_2D, this.textures[txtrindex]);
GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, (int)GL.GL_RGB, image.Width, image.Height, 0, GL.GL_BGR_EXT, GL.GL_UNSIGNED_BYTE, bitmapdata.Scan0);
image.UnlockBits(bitmapdata);
image.Dispose();
return true;
}
return false;
} }
AUX_RGBImageRec *LoadBMP(char *Filename) // Loads A Bitmap Image
{
FILE *File=NULL; // File Handle
if (!Filename) // Make Sure A Filename Was Given
{
return NULL; // If Not Return NULL
}
File=fopen(Filename,"r"); // Check To See If The File Exists
if (File) // Does The File Exist?
{
fclose(File); // Close The Handle
return auxDIBImageLoad(Filename); // Load The Bitmap And Return A Pointer
}
return NULL; // If Load Failed Return NULL
}
BOOL LoadTexture(std::string filename, int index)
{
int Status=FALSE; // Status Indicator
AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture
memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL
// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
if (TextureImage[0]=LoadBMP((char*)filename.c_str()))
{
Status=TRUE; // Set The Status To TRUE
// Create Linear Filtered Texture
glBindTexture(GL_TEXTURE_2D, texture[index]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
}
if (TextureImage[0]) // If Texture Exists
{
if (TextureImage[0]->data) // If Texture Image Exists
{
free(TextureImage[0]->data); // Free The Texture Image Memory
}
free(TextureImage[0]); // Free The Image Structure
}
return Status; // Return The Status
}