#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glaux.h>
#include <gl/glut.h>
//////////////////////////////////////////////////////////////////
// constants
//////////////////////////////////////////////////////////////////
#define xWindowWidth 800
#define xWindowHeight 600
bool xFullScreen = false;
//////////////////////////////////////////////////////////////////
// Function Prototyps
//////////////////////////////////////////////////////////////////
GLvoid InitGL(GLvoid);
GLvoid DrawGLScene(GLvoid);
GLvoid ResizeGLScene(GLsizei width, GLsizei height);
GLvoid KeyPress(unsigned char key, int px, int py);
GLvoid InitWindow(GLvoid);
int main(int argc, char ** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
//glutGameModeString("800x600:32@60");
//glutEnterGameMode();
glutInitWindowSize(xWindowWidth, xWindowHeight);
glutInitWindowPosition(100, 100);
glutCreateWindow("Code Shell");
InitGL();
InitWindow();
glutMainLoop();
return 0;
}
GLvoid InitGL(GLvoid) {
glShadeModel(GL_SMOOTH);
glClearColor(0.8f, 0.8f, 0.9f, 0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}
GLvoid InitWindow(GLvoid) {
glutDisplayFunc(DrawGLScene);
glutReshapeFunc(ResizeGLScene);
glutIgnoreKeyRepeat(1);
glutKeyboardFunc(KeyPress);
ResizeGLScene(xWindowWidth, xWindowHeight); //called to force Projection
}
GLvoid DrawGLScene(GLvoid) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity();
glPushMatrix(); //saves matrix to stack
glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0
glBegin(GL_TRIANGLES); // Drawing Using Triangles
glColor3f(1.0f,0.0f,0.0f);
glVertex3f( 0.0f, 1.0f, 0.0f); // Top
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glColor3f(0.0f,0.0f,1.0f);
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glColor3f(0.0f,0.0f,0.0f);
glEnd();
glPopMatrix(); //restores matrix from stack
glutSwapBuffers();
}
GLvoid ResizeGLScene(GLsizei width, GLsizei height) {
if(height == 0)
height = 1;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
GLvoid KeyPress(unsigned char key, int px, int py) {
if(key == 13 && glutGetModifiers() == GLUT_ACTIVE_ALT) { //alt + enter go fullscreen
if(xFullScreen == false) {
glutGameModeString("800x600:32@60");
glutEnterGameMode();
InitGL();
InitWindow();
glutSetCursor(GLUT_CURSOR_NONE);
}else{
glutLeaveGameMode();
}
xFullScreen = !xFullScreen;
}
}
Ok this is edited now....
It works when i press alt+enter to go fullscreen, however it leaves the original window there too. Is the original window going to be hendering performance in the future? Or will it not matter because its no longer active. Is there a way to get rid of the original window and when i press alt enter again it comes back? I know this is a really simple program, but i figured my base code for all future programs better start off right in the first place.
[edited by - justinwalsh on November 10, 2003 9:52:13 PM]
GLUT : Help Gamemode problems!! see code inside
ok well after all this time spent with glut, it looks like i must ditch it. Glut will not hardware accelerate on my win32 computer. If anyone knows why let me know, i can run quake3 just fine at 100''s of frames per second, but i cant even render a spinning cube at more than about 20-30 in 800x600 mode.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement