000
28.02.2006, 20:21 Uhr
WindDancer1
|
Hallo Leutz!=-) Ich habe ein NeHe Tut http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=11 durchgearbeitet, in dem eine Bitmap wie eine Flagge wackelt. Mein Problem ist, dass das Beispiel mit einem quadratischen Bild arbeitet und ich jetzt aber ein rechteckiges Bild verwenden möchte. Mein Bild wird dann aber quadratisch angezeigt. Was muss ich ändern, damit mein Bild nicht verzerrt wird???
Vielen Dank im vorraus! WindDancer
C++: |
void initwave() {
if (!LoadTGA(&textures[0],"Kopie.TGA")) // Lade die Font Textur { return; }
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping ( NEW ) glShadeModel(GL_SMOOTH); // Enable Smooth Shading glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background glClearDepth(1.0f); // Depth Buffer Setup glEnable(GL_DEPTH_TEST); // Enables Depth Testing glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations glPolygonMode( GL_BACK, GL_FILL ); // Back Face Is Filled In glPolygonMode( GL_FRONT, GL_LINE ); // Front Face Is Drawn With Lines
// Loop Through The X Plane for(int x=0; x<45; x++) { // Loop Through The Y Plane for(int y=0; y<45; y++) { // Apply The Wave To Our Mesh points[x][y][0]=float((x/5.0f)-4.5f); points[x][y][1]=float((y/5.0f)-4.5f); points[x][y][2]=float(sin((((x/5.0f)*40.0f)/360.0f)*3.141592654*2.0f)); } }
}
void wave() { int x, y; // Loop Variables float float_x, float_y, float_xb, float_yb; // Used To Break The Flag Into Tiny Quads glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And Depth Buffer glLoadIdentity(); // Reset The Current Matrix
glTranslatef(0.0f,0.0f,-12.0f); // Translate 12 Units Into The Screen
glBindTexture(GL_TEXTURE_2D, textures[0].texID); // Select Our Texture glBegin(GL_QUADS); // Start Drawing Our Quads for( x = 0; x < 44; x++ ) // Loop Through The X Plane (44 Points) { for( y = 0; y < 44; y++ ) // Loop Through The Y Plane (44 Points) { float_x = float(x)/44.0f; // Create A Floating Point X Value float_y = float(y)/44.0f; // Create A Floating Point Y Value float_xb = float(x+1)/44.0f; // Create A Floating Point Y Value+0.0227f float_yb = float(y+1)/44.0f; // Create A Floating Point Y Value+0.0227f
glTexCoord2f( float_x, float_y); // First Texture Coordinate (Bottom Left) glVertex3f( points[x][y][0], points[x][y][1], points[x][y][2] ); glTexCoord2f( float_x, float_yb ); // Second Texture Coordinate (Top Left) glVertex3f( points[x][y+1][0], points[x][y+1][1], points[x][y+1][2] ); glTexCoord2f( float_xb, float_yb ); // Third Texture Coordinate (Top Right) glVertex3f( points[x+1][y+1][0], points[x+1][y+1][1], points[x+1][y+1][2] ); glTexCoord2f( float_xb, float_y ); // Fourth Texture Coordinate (Bottom Right) glVertex3f( points[x+1][y][0], points[x+1][y][1], points[x+1][y][2] ); } } glEnd(); // Done Drawing Our Quads if( wiggle_count == 2 ) // Used To Slow Down The Wave (Every 2nd Frame Only) { for( y = 0; y < 45; y++ ) // Loop Through The Y Plane { hold=points[0][y][2]; // Store Current Value One Left Side Of Wave for( x = 0; x < 44; x++) // Loop Through The X Plane { // Current Wave Value Equals Value To The Right points[x][y][2] = points[x+1][y][2]; } points[44][y][2]=hold; // Last Value Becomes The Far Left Stored Value } wiggle_count = 0; // Set Counter Back To Zero } wiggle_count++; // Increase The Counter }
|
|