
GLUT Test
By: a guest on
Sep 24th, 2012 | syntax:
C++ | size: 1.65 KB | hits: 62 | expires: Never
#include <windows.h>
#include <GL/freeglut.h>
#include <GL/freeglut_ext.h>
#include <GL/freeglut_std.h>
#include <iostream>
#include <stdlib.h>
void renderScene(void);
void keyboard(unsigned char c, int x, int y);
double posX = 50;
double posY = 50;
double speedX = 5;
double speedY = 5;
int main(int argc, char *argv[])
{
//Init GLUT and create window
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(800,600);
glutCreateWindow("GLUT Test");
gluOrtho2D(0,800,0,600);
//register callbacks
glutDisplayFunc(renderScene);
//Main draw loop when window is not resized
glutIdleFunc(renderScene);
//Keyboard input
glutKeyboardFunc(keyboard);
//enter GLUT event processing cycle
glutMainLoop();
return 0;
}
void keyboard(unsigned char c, int x, int y)
{
if(c == 'w')
posY += speedY;
if(c == 'a')
posX -= speedX;
if(c == 's')
posY -= speedY;
if(c == 'd')
posX += speedX;
}
void renderScene()
{
//std::cout << "updating" << std::endl;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//x += .01;
std::cout << posX;
std::cout << " , ";
std::cout << posY << std::endl;
glColor4f(0,.5,0,1);
glBegin(GL_QUADS);
glVertex2d(posX, posY);
glVertex2d(posX, posY + 50);
glVertex2d(posX + 50, posY + 50);
glVertex2d(posX + 50, posY);
glEnd();
glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)'t');
glutSwapBuffers();
}