66 lines
1.4 KiB
C++
66 lines
1.4 KiB
C++
|
|
/* Libraries we use */
|
|
#include <GL/gl.h>
|
|
#include <GL/glu.h>
|
|
|
|
/* Some definitions */
|
|
#define WIDTH 800
|
|
#define HEIGHT 800
|
|
#define TITLE "Josh's Wavefront Object Viewer"
|
|
|
|
/* Some function prototypes */
|
|
void display(void);
|
|
void mouse(int button, int state, int x, int y);
|
|
void motion(int x, int y);
|
|
|
|
/* Some global variables */
|
|
float rotationMatrix[16];
|
|
int startx, starty;
|
|
|
|
/* The program's main entry point */
|
|
int main(int argc, char *argv[])
|
|
{
|
|
/* OpenGL initialization */
|
|
glShadeModel(GL_SMOOTH);
|
|
glEnable(GL_DEPTH_TEST);
|
|
glEnable(GL_LIGHTING);
|
|
glEnable(GL_LIGHT0);
|
|
float lpos[] = {0.0f, -6.0f, 0.0f, 1.0f};
|
|
glLightfv(GL_LIGHT0, GL_POSITION, lpos);
|
|
glEnable(GL_CULL_FACE);
|
|
glClearColor(0, .3, 0.5, 1);
|
|
/* Initialize the default rotation matrix */
|
|
glMatrixMode(GL_MODELVIEW);
|
|
glLoadIdentity();
|
|
glGetFloatv(GL_MODELVIEW_MATRIX, rotationMatrix);
|
|
return 0;
|
|
}
|
|
|
|
/* This function is called to display the scene each refresh */
|
|
void display(void)
|
|
{
|
|
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
|
glLoadIdentity();
|
|
glMultMatrixf(rotationMatrix);
|
|
}
|
|
|
|
/* handle mouse button press/release events */
|
|
void mouse(int button, int state, int x, int y)
|
|
{
|
|
startx = x;
|
|
starty = y;
|
|
}
|
|
|
|
/* handle mouse motion events */
|
|
void motion(int x, int y)
|
|
{
|
|
glLoadIdentity();
|
|
glRotatef(y-starty, 1, 0, 0);
|
|
glRotatef(x-startx, 0, 0, 1);
|
|
glMultMatrixf(rotationMatrix);
|
|
glGetFloatv(GL_MODELVIEW_MATRIX, rotationMatrix);
|
|
startx=x;
|
|
starty=y;
|
|
}
|
|
|