24 Aug 2012

OPENGL C++

Demonstrates basic use of GLUT toolkit for CS248 video game assignment: theLink

glutTimerFunc(): LINK

glutGet(GLUT_ELAPSED_TIME): LINK 1

glutGet(GLUT_ELAPSED_TIME) @ gamedev.net

23 Aug 2012

Mavis Vermilion


Fairy Tail CH 289


Fairy Tail CH 290


Mavis crying


Fairy Tail CH 292


3 Aug 2012

Right Click Menu

//-------------------------------------------------------------------------
// Draw skybox
//-------------------------------------------------------------------------
#include < ::iostream >
#include "myengine.h"
#include "GL/glut.h"
#include "GL/freeglut.h"

#include < ::windows.h > // WinApi header
#include < ::mmsystem.h>

/* process menu option 'op' */
void menu(int op)
{
switch(op) {
case 'Q':
case 'q':
exit(0);
break;
default:
break;
}
}

/* executed when a regular key is pressed */
void keyboardDown(unsigned char key, int x, int y)
{
switch(key) {
case 'Y':
case 'y':
PlaySound(TEXT("tada.wav"), NULL, SND_ASYNC | SND_LOOP); // music
break;

case 'N':
case 'n':
PlaySound(NULL, 0, 0); // stop music
break;

case 'Q':
case 'q':
case 27: // ESC
exit(0);
break;
}
}

/* executed when a special key is pressed */
void keyboardSpecialDown(int k, int x, int y) {

}

/* reshaped window */
void reshape(int width, int height) {

GLfloat fieldOfView = 90.0f;
glViewport (0, 0, (GLsizei) width, (GLsizei) height);

glMatrixMode (GL_PROJECTION);
glLoadIdentity();
gluPerspective(fieldOfView, (GLfloat) width/(GLfloat) height, 0.1, 1000.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

/* executed when button 'button' is put into state 'state' at screen position ('x', 'y') */
void mouseClick(int button, int state, int x, int y) {

}

/* executed when the mouse moves to position ('x', 'y') */
void mouseMotion(int x, int y) {

}

/* render the scene */
void RenderScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearDepth( 1.0 );
glEnable( GL_DEPTH_TEST );
glDepthFunc( GL_LESS );
glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

/* render the scene here */
glColor3f(0.8f,0.0f,1.0f);
glBegin(GL_QUADS); // draw background quad
glVertex3f(-2.0f, 1.0f, -8.0f);
glVertex3f( 1.0f, 1.0f, -8.0f);
glVertex3f( 1.0f,-1.0f, -8.0f);
glVertex3f(-2.0f,-1.0f, -8.0f);
glEnd();

glFlush();
glDisable( GL_DEPTH_TEST );
glutSwapBuffers();
}

/* executed when program is idle */
void idle() {

}

/* initialize OpenGL settings */
void initGL(int width, int height)
{
//reshape(width, height);

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glShadeModel( GL_SMOOTH );
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
glDepthFunc(GL_LEQUAL);
}

/* initialize GLUT settings, register callbacks, enter main loop */
int main(int argc, char** argv)
{
glutInit(&argc, argv);

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize( 800, 600 );
glutInitWindowPosition(100, 100);
glutCreateWindow("Perspective's GLUT Template");

// register glut call backs
glutKeyboardFunc( keyboardDown );
glutSpecialFunc( keyboardSpecialDown );
glutMouseFunc( mouseClick );
glutMotionFunc( mouseMotion );
glutReshapeFunc( reshape);
glutDisplayFunc( RenderScene );
glutIdleFunc( idle );
glutIgnoreKeyRepeat(true); // ignore keys held down

// create a sub menu
int subMenu = glutCreateMenu(menu);
glutAddMenuEntry("No", 0);
glutAddMenuEntry("Yes", 'q');

// create main "right click" menu
glutCreateMenu(menu);
glutAddSubMenu("Quit?", subMenu);
//glutAddMenuEntry("Quit", 'q');
glutAttachMenu(GLUT_RIGHT_BUTTON);

initGL(800, 600);

glutMainLoop();
return 0;
}