home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OpenGL Superbible
/
OpenGL_Superbible_Waite_Group_Press_1996.iso
/
book
/
chapt3
/
scale
/
scale.c
next >
Wrap
C/C++ Source or Header
|
1996-03-08
|
1KB
|
63 lines
// Scale.c
// Scaling an OpenGL Window.
#include <windows.h> // Standard Windows header
#include <gl\gl.h> // OpenGL Library
#include <gl\glaux.h> // AUX Library
// Called by AUX Library when the window has changed size
void CALLBACK ChangeSize(GLsizei w, GLsizei h)
{
// Prevent a divide by zero
if(h == 0)
h = 1;
// Set Viewport to window dimensions
glViewport(0, 0, w, h);
// Reset coordinate system
glLoadIdentity();
// Establish clipping volume (left, right, bottom, top, near, far)
if (w <= h)
glOrtho (0.0f, 250.0f, 0.0f, 250.0f*h/w, 1.0, -1.0);
else
glOrtho (0.0f, 250.0f*w/h, 0.0f, 250.0f, 1.0, -1.0);
}
// Called by the AUX Library whenever the window
// needs to be updated
void CALLBACK RenderScene(void)
{
// Set background color to blue
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
// OpenGL or AUX Library drawing code
glClear(GL_COLOR_BUFFER_BIT);
// Draws a Red Rectangle
glColor3f(1.0f, 0.0f, 0.0f);
glRectf(100.0f, 150.0f, 150.0f, 100.0f);
glFlush();
}
void main(void)
{
// Setup and initialize AUX window
auxInitDisplayMode(AUX_SINGLE | AUX_RGBA);
auxInitPosition(100,100,250,250);
auxInitWindow("Scaling Window");
// Set function to call when window changes size
auxReshapeFunc(ChangeSize);
// Set function to call when window needs updating
auxMainLoop(RenderScene);
}