Loading Bitmap
I seem to be having a problem. The following code compiles, everything shows up that I want, except for my alien.ms3d file. Everything compiles, my grid shows up, only my alien doesn't show up. Can someone help me out?
BTW, the lesson31.h, MilkShapeModel.h files are the same ones from this site in lesson 31. And all the cpp files in lesson 31 are a part of this file. Thanks for the help.
#include <GL/glut.h>
#include <stdlib.h>
#include <FPshooter.h>
#include <MilkshapeModel.h>
#include <lesson31.h>
#include <windows.h> // Header File For Windows
#include <stdio.h> // Header File For Standard Input/Output
#include <gl\gl.h> // Header File For The OpenGL32 Library
#include <gl\glu.h> // Header File For The GLu32 Library
#include <glaux.h>
#define PI 3.1415926535898
double view_angle = PI*1.5, sight = 0;
Model *pModel = NULL;
using namespace std;
AUX_RGBImageRec *LoadBMP(const 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
}
GLuint LoadGLTexture( const char *filename ) // Load Bitmaps And Convert To Textures
{
AUX_RGBImageRec *pImage; // Create Storage Space For The Texture
GLuint texture = 0; // Texture ID
pImage = LoadBMP( filename ); // Loads The Bitmap Specified By filename
// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
if ( pImage != NULL && pImage->data != NULL ) // If Texture Image Exists
{
glGenTextures(1, &texture); // Create The Texture
// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, 3, pImage->sizeX, pImage->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, pImage->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
free(pImage->data); // Free The Texture Image Memory
free(pImage); // Free The Image Structure
}
return texture; // Return The Status
}
void init(void)
{
pModel->reloadTextures();
GLfloat mat_specular[]={0.5,0.5,0.5,1.0}; //Set the light...
GLfloat light_position[]={3.0,4.0,10.0,0.0}; //If i want to add more lights later i can
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialf(GL_FRONT, GL_SHININESS, 80.0);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glColorMaterial(GL_FRONT, GL_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LINE_SMOOTH);
}
void drawString (const char *s) //How do display text
{
unsigned int i;
for (i = 0; i < strlen (s); i++)
glutBitmapCharacter (GLUT_BITMAP_HELVETICA_18, s);
};
void reshape(int w, int h)
{
glViewport(0,0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w<=h)
{
glOrtho(-1.5,1.5,-1.5*(GLfloat)h/(GLfloat)w, 1.5*(GLfloat)h/(GLfloat)w, -10.0,10.0);
}
else
{
glOrtho(-1.5*(GLfloat)w/(GLfloat)h, 1.5*(GLfloat)w/(GLfloat)h, -1.5,1.5,-10.0,10.0);
}
glMatrixMode(GL_MODELVIEW);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(450,(float)w/h,0.1,100);
glMatrixMode(GL_MODELVIEW);
}
void display(void)
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glLoadIdentity();
gluLookAt(0,0,0,cos(view_angle), sin(sight), sin(view_angle), 0,10,0);
pModel->loadModelData( "data/model.ms3d" );
pModel->draw();
glPushMatrix();
glColor3f(1.0,0.0,0.0);
glLineWidth(1.0);
glBegin(GL_LINES);
for(int i=-100;i<=100;++i)
{
glVertex3f(i,-3,-100);
glVertex3f(i,-3,100);
glVertex3f(100,-3,i);
glVertex3f(-100,-3,i);
}
glEnd();
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void Keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case ' ':
break;
case 'w':
break;
case 'd':
view_angle+=PI/30;
break;
case 'a':
view_angle-=PI/30;
break;
case 's':
break;
case 27: // *this is the escape key*, escape
exit(0);
break;
default:
break;
}
glutPostRedisplay();
}
void mouse(int button, int state, int x, int y)
{
switch(button)
{
case GLUT_LEFT_BUTTON:
if(state==GLUT_DOWN)
{
}
break;
default:
break;
}
}
void processMousePassiveMotion(int x, int y)
{
}
int main(int argc, char *argv[])
{
pModel = new MilkshapeModel();
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(640,480);
glutInitWindowPosition(200,200);
glutCreateWindow("Milk Learn");
init();
//glutFullScreen( );
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(Keyboard);
glutMouseFunc(mouse);
glutPassiveMotionFunc(processMousePassiveMotion);
//glutSetCursor( GLUT_CURSOR_NONE );
glutMainLoop();
return 0;
}
Mitchen Games
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement