001
11.06.2004, 21:13 Uhr
FloSoft
Medialer Over-Flow (Administrator)
|
Hi, das problem kenn ich. Bei folgendem Würfel passiert dies glaube ich nicht, musst du mal testen:
C++: |
#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 <gl\glaux.h> // Header File For The GLaux Library
class Vector3D { public: Vector3D(GLfloat x,GLfloat y,GLfloat z); GLfloat x; GLfloat y; GLfloat z; };
Vector3D::Vector3D(GLfloat xl,GLfloat yl,GLfloat zl) { x = xl; y = yl; z = zl; }
#define TEXTURE_MAX 6
HDC hDC = NULL; // Permanent Rendering Context HWND hWnd = NULL; // Private GDI Device Context HGLRC hRC = NULL; // Holds Our Window Handle
bool keys[256]; // Array Used For The Keyboard Routine bool active = TRUE; // Window Active Flag Set To TRUE By Default bool fullscreen = TRUE; // Fullscreen Flag Set To Fullscreen Mode By Default
Vector3D rot(0.0f,128.0f,45.0f); // Rotation
Vector3D pos(0.0f,0.0f,-5.0f); // Position
GLuint texture[TEXTURE_MAX]; // Storage For One Texture
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc
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 }
int LoadGLTextures() // Load Bitmaps And Convert To Textures { int Status=FALSE; // Status Indicator int loop = 0; AUX_RGBImageRec *TextureImage[TEXTURE_MAX]; // Create Storage Space For The Texture memset(TextureImage,0,sizeof(void *)*TEXTURE_MAX); // Set The Pointer To NULL char filename[_MAX_PATH]; for(loop=1; loop<TEXTURE_MAX+1; loop++) { sprintf(filename,"bitmap%d.bmp",loop); TextureImage[loop-1]=LoadBMP(filename); } Status=TRUE; // Set The Status To TRUE glGenTextures(TEXTURE_MAX, &texture[0]); // Create Two Texture for (loop=0; loop<TEXTURE_MAX; loop++) { glBindTexture(GL_TEXTURE_2D, texture[loop]); 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, 3, TextureImage[loop]->sizeX, TextureImage[loop]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[loop]->data); } for (loop=0; loop<TEXTURE_MAX; loop++) { if (TextureImage[loop]) // If Texture Exists { if (TextureImage[loop]->data) // If Texture Image Exists { free(TextureImage[loop]->data); // Free The Texture Image Memory } free(TextureImage[loop]); // Free The Image Structure } } return Status; // Return The Status }
GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window { if (height==0) // Prevent A Divide By Zero By { height=1; // Making Height Equal One } glViewport(0, 0, width, 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(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f); glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix glLoadIdentity(); // Reset The Modelview Matrix }
int InitGL(GLvoid) // All Setup For OpenGL Goes Here { if (!LoadGLTextures()) // Jump To Texture Loading Routine { return FALSE; // If Texture Didn't Load Return FALSE } glEnable(GL_TEXTURE_2D); // Enable Texture Mapping glShadeModel(GL_SMOOTH); // Enables Smooth Shading glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background glClearDepth(1.0); // Depth Buffer Setup glEnable(GL_DEPTH_TEST); // Enables Depth Testing glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations return TRUE; // Initialization Went OK }
int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(pos.x,pos.y,pos.z); // xrot = 45.0f; // yrot = 45.0f; // zrot = 45.0f; glRotatef(rot.x,1.0f,0.0f,0.0f); // Rotate On The X Axis glRotatef(rot.y,0.0f,1.0f,0.0f); // Rotate On The Y Axis glRotatef(rot.z,0.0f,0.0f,1.0f); // Rotate On The Z Axis glBindTexture(GL_TEXTURE_2D, texture[0]); // Bitmap mit 1 glBegin(GL_QUADS); // Front Face glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[5]); // Bitmap mit 6 glBegin(GL_QUADS); // Back Face glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[4]); // Bitmap mit 5 glBegin(GL_QUADS); // Top Face glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[1]); // Bitmap mit 2 glBegin(GL_QUADS); // Bottom Face glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[2]); // Bitmap mit 3 glBegin(GL_QUADS); // Right face glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[3]); // Bitmap mit 4 glBegin(GL_QUADS); // Left Face glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glEnd(); // xrot += 0.1f; // yrot += 0.1f; // zrot += 0.1f; return TRUE; }
|
-- class God : public ChuckNorris { }; |