www.pudn.com > ÈýάÌì¿ÕÓëµØÐÎ.zip > oglInit.cpp, change:2001-10-15,size:2835b
// SkyDome Demo - October 2001
//
// Luis R. Sempé
// visual@spheregames.com
// Sphere Games (http://www.spheregames.com)
//
// You may use, copy, distribute or create derivative software
// for any purpose. If you do, I'd appreciate it if you write me
// and let me know what you do with it. Thanks!
// Have fun!
////////////////////////////////////////////////////
#include <stdio.h>
#include "oglInit.h"
#include "globals.h"
#include "SkyDome.h"
#include "Terrain.h"
#include "SkyPlane.h"
GLuint texture[2];
GLvoid ResizeGLWindow(GLsizei width, GLsizei height)
{
if (height == 0) height = 1;
// sets the viewport's size
glViewport(0,0,width,height);
// set the projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)(width/height), 0.1f, 2000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
GLint InitGL(GLvoid)
{
glEnable(GL_TEXTURE_2D);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Fog
GLfloat fogColor[4]= {0.9f, 0.9f, 0.9f, 0.6f};
glFogi(GL_FOG_MODE, GL_LINEAR);
glFogfv(GL_FOG_COLOR, fogColor);
glFogf(GL_FOG_DENSITY, 0.002f);
glFogf(GL_FOG_START, 100.0f);
glFogf(GL_FOG_END, 800.0f);
glHint(GL_FOG_HINT, GL_FASTEST);
LoadTextures("clouds2.bmp", 0);
LoadTextures("sand3.bmp", 1);
GenerateDome(600.0f, 5.0f, 5.0f, 1.0f, 1.0f);
GenerateSkyPlane(16, 500.0f, 900.0f, 1.0f, 1.0f);
GenerateTerrain();
return true;
}
int LoadTextures(char *filename, int id)
{
int status = false;
AUX_RGBImageRec *TextureImage = NULL;
ZeroMemory(&TextureImage, sizeof(void*)*1);
if (TextureImage = LoadBMP(filename))
{
status = true;
glGenTextures(1, &texture[id]);
glBindTexture(GL_TEXTURE_2D, texture[id]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage->sizeX, TextureImage->sizeY,
0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage->data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
if (TextureImage)
{
if (TextureImage->data)
free(TextureImage->data);
free(TextureImage);
}
return status;
}
AUX_RGBImageRec *LoadBMP(char *filename)
{
FILE *file = NULL;
if (!filename)
return NULL;
file = fopen(filename, "r");
if (file)
{
fclose(file);
return auxDIBImageLoad(filename);
}
return NULL;
}
void Move(float px, float py, float pz, float roll,
float pitch, float heading)
{
glRotatef(roll, 0.0f, 0.0f, 1.0f);
glRotatef(pitch, 0.0f, 1.0f, 0.0f);
glRotatef(heading, 1.0f, 0.0f, 0.0f);
glTranslatef(-px, -py, -pz);
}