Created
December 4, 2013 19:12
-
-
Save nixpulvis/7793609 to your computer and use it in GitHub Desktop.
Fullscreen OpenGL with GLUT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if defined(__APPLE__) | |
#include <OpenGL/gl.h> | |
#include <OpenGL/glu.h> | |
#else | |
#include <GL/gl.h> | |
#include <GL/glu.h> | |
#endif | |
#include <GLUT/glut.h> | |
#include <stdio.h> | |
int is_fullscreen = 0; | |
int pos_x = 100; | |
int pos_y = 100; | |
void display(void) { | |
glClearColor(1,1,1,0); | |
glClear(GL_COLOR_BUFFER_BIT); | |
glBegin(GL_TRIANGLES); | |
{ | |
glColor3f(1,0,0); | |
glVertex2f(0,0); | |
glColor3f(0,1,0); | |
glVertex2f(.5,0); | |
glColor3f(0,0,1); | |
glVertex2f(.5,.5); | |
} | |
glEnd(); | |
glutSwapBuffers(); | |
} | |
void idle(void) { | |
if (!is_fullscreen) { | |
pos_x = glutGet(GLUT_WINDOW_X); | |
pos_y = glutGet(GLUT_WINDOW_Y); | |
} | |
} | |
void toggle_fullscreen() { | |
if (is_fullscreen) { | |
glutReshapeWindow(1000, 625); | |
glutPositionWindow(pos_x, pos_y); | |
printf("%d, %d\n", pos_x, pos_y); | |
} else { | |
glutFullScreen(); | |
} | |
is_fullscreen = !is_fullscreen; | |
} | |
void reshape(int x, int y) { | |
printf("Resizing to... %d, %d\n", x, y); | |
} | |
void keyboard(unsigned char key, int x, int y) { | |
switch (key) { | |
case 'f': | |
toggle_fullscreen(); | |
break; | |
} | |
} | |
int main(int argc, char *argv[]) { | |
glutInit(&argc, argv); | |
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); | |
glutCreateWindow("My Game"); | |
glutReshapeWindow(900, 600); | |
glutPositionWindow(pos_x, pos_y); | |
glutDisplayFunc(display); | |
glutReshapeFunc(reshape); | |
glutIdleFunc(idle); | |
glutKeyboardFunc(keyboard); | |
glutMainLoop(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment