PDA

View Full Version : load bmp, other than windows bmp.



01-29-2001, 08:59 AM
hi everyone and Simon
this is a program to load a bmp. it works well enough but only with windows in built bmps. if i try to load and ACDSee wall paper by converting it to 256 colors image first, it doesnt load the bmp.

here is the code:

/*Texture Mapping*/
#include <windows.h> // Header File For Windows
#include <gl\glut.h> // Header File For The GLu32 Library
#include <gl\glaux.h> // Header File For The GLaux Library


GLuint texture[1]; // Storage for 1 texture


// Load Bitmaps And Convert To Textures
GLvoid LoadGLTextures()
{
// Load Texture
AUX_RGBImageRec *texture1;
texture1 = auxDIBImageLoad("new-2.bmp");
if (!texture1) exit(1);

// Create Texture
glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, texture1->sizeX, texture1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, texture1->data);
}

GLvoid InitGL(GLvoid) // All Setup For OpenGL Goes Here
{
LoadGLTextures(); // Load The Texture(s)
glShadeModel(GL_FLAT); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
glFlush();
}

void DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(0.0f,0.0f,-5.0f);
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glBindTexture(GL_TEXTURE_2D, texture[0]);

glBegin(GL_POLYGON);
glTexCoord2f(6.0f, 0.0f); glVertex3f(-1.0f,-1.0f,-1.0f);
glTexCoord2f(6.0f, 6.0f); glVertex3f(-1.0f,1.0f,-1.0f);
glTexCoord2f(0.0f, 6.0f); glVertex3f(1.0f,1.0f,-1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(1.0f,-1.0f,-1.0f);
glEnd();
glFlush();
glDisable(GL_TEXTURE_2D);
}


GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window
{
glViewport(0,0,(GLsizei)width,(GLsizei)height); // Reset The Current Viewport
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
// Calculate The Aspect Ratio Of The Window
gluPerspective(60.0,(GLfloat)width/(GLfloat)height,1.0,100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

}


int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPT H);
glutInitWindowSize(300,300);
glutInitWindowPosition(100,100);
glutCreateWindow("Project");
InitGL();
glutDisplayFunc(DrawGLScene);
glutReshapeFunc(ReSizeGLScene);
glutMainLoop();
return 0;
}

any modifications to load any bmp.
thanks a lot in advance!
anxious

Michael Steinberg
01-29-2001, 09:46 AM
Well, I didn't use this aux function yet, but I wrote my own 1/4/16/24 (and maybe 32bit) bmp loader. If you want it, drop me a line.

dans
01-29-2001, 11:10 AM
You are asking to load a 24bit bitmap and only giving it a 256 color bitmap. Convert your bmp to 24 bit and it should be right.

01-29-2001, 07:52 PM
Originally posted by dans:
You are asking to load a 24bit bitmap and only giving it a 256 color bitmap. Convert your bmp to 24 bit and it should be right.


could u plz elaborate ur point. i couldnt understand it. it loads only 256 colors windows bmp, and none others.

dans
02-15-2001, 02:07 PM
Sorry for the long delay here, i lost this message. Are you still seeking information on this?