// ***************************************************
// ** Creates 3 Boxes **
// ***************************************************
// used later when the FALCON is connected
//#include <windows.h>
//#include "glut.h"
//#include <math.h>
//#include "haptics.h"
#include <stdlib.h>
#include <GL/openglut.h>
//#include <GL/glut.h>
#include <stdio.h>
#include <iostream>
using namespace std;
int w, h;
// if the window size is changed, the objects inside will be resized as well
void changeSize(int w, int h) {
// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
if (h == 0)
h = 1;
double ratio = w * 1.0 / h; // changed 'float' to 'double' due to warning
// Use the Projection Matrix
glMatrixMode(GL_PROJECTION);
// Reset Matrix
glLoadIdentity();
// Set the viewport to be the entire window
glViewport(0, 0, w, h);
// Set the correct perspective.
gluPerspective(45, ratio, 0.1, 100);
// Get Back to the Modelview
glMatrixMode(GL_MODELVIEW);
}
// exit out by pressing 'ESC' key
void glutKeyboard(unsigned char key, int x, int y) {
static bool inited = true;
if (key == 27) // esc key
{
exit(0);
}
}
void renderBitmapString (float x, float y, float z, void *font, char *string) {
char *c;
glRasterPos3f(x, y, z);
for (c = string; *c != '\0'; c++) {
glutBitmapCharacter(font, *c);
}
}
void restorePerspectiveProjection() {
glMatrixMode(GL_PROJECTION);
// restore previous projection matrix
glPopMatrix();
// get back to modelview mode
glMatrixMode(GL_MODELVIEW);
}
void setOrthographicProjection() {
// switch to projection mode
glMatrixMode(GL_PROJECTION);
// save previous matrix which contains the
// settings for the perspective projection
glPushMatrix();
// reset matrix
glLoadIdentity();
// set a 2D orthographic projection
gluOrtho2D(0, w, h, 0);
// switch back to modelview mode
glMatrixMode(GL_MODELVIEW);
}
// creates three boxes and text
void renderScene(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// draw three boxes
glTranslated(2, 0, -5);
glutWireCube(0.5);
glTranslated(-2, 0, -5);
glutWireCube(0.5);
glTranslated(1, 2, -5);
glutWireCube(0.5);
// Code to display a string (fps) with bitmap fonts
setOrthographicProjection();
glPushMatrix();
glLoadIdentity();
renderBitmapString(1.0f, 2.0f , -5.0f, GLUT_BITMAP_HELVETICA_18, "HELLO");
glPopMatrix();
restorePerspectiveProjection();
glutSwapBuffers();
}
int main(int argc, char **argv) {
// init GLUT, create Window and init Keyboard
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(900, 400);
glutCreateWindow("THREE BOXES DEMO");
glutKeyboardFunc(glutKeyboard);
// register callbacks
glutDisplayFunc(renderScene);
renderBitmapString(0.1f, 0.1f, 0.1f, GLUT_BITMAP_TIMES_ROMAN_10, "hello");
glutReshapeFunc(changeSize);
// enter GLUT event processing cycle
glutMainLoop();
}