Featured Posts

8. Bump Mapping in GLSL8. Bump Mapping in GLSL Introduction Bump mapping is essential in todays computer games, and computer graphics in general. Would you like to know the best thing about it? It is extremely simple to implement. Bump mapping works...

Read more

Swiftless GLSL Shader DeveloperSwiftless GLSL Shader Developer Swiftless GLSL Shader Developer   Version 0.1a Currently Swiftless GLSL Shader Developer is in it's first public release, and is currently in alpha status, meaning it is not complete and may contain...

Read more

Wordpress Optimization Wordpress Website Optimizations Introduction Wordpress itself is a fairly wonderful tool. Since switching to it, I find it is a lot quicker to make changes to my website and it is also quicker to get...

Read more

36. OpenGL Framebuffers36. OpenGL Framebuffers Introduction Frame buffers are one of those mythical things that we have all heard of, but many beginner OpenGL developers avoid because there is not much information about them, and they can be confusing...

Read more

1. Terrain Class1. Terrain Class Terrain is one of those things that so far, hasn't been perfectly recreated in computer graphics. But it is almost there! Looking over a beautiful landscape can be one of the most amazing feelings in the...

Read more

  • Prev
  • Next

19. OpenGL Fullscreen Mode

Posted on : 25-03-2010 | By : Swiftless | In : OpenGL

Tags: , , ,

4

In this opengl tutorial I will be teaching you how to set your games into fullscreen mode using glut. This is often used to increase the amount of frames per second in a game, along with setting the quality of the picture. A lower resolution in fullscreen mode means a worse looking picture. Fullscreen mode in GLUT is probably one of the easiest things you can do
just before you call the line to enter glut fullscreen mode you choose
which settings to use when in glut fullscreen mode.

Such as the resolution,
color depth and the refresh rate.
we do this with:
glutGameModeString( “990×768:32@75″ );
this is setting the resolution to 990×768, you can also use 800×600, 640×480, etc
next it is saying to use a color depth of 32 bits, you can also use 24, 16, 8, etc
then it is telling the program to run the screen refresh rate at 75hertz, others are 65, 70, 80, 85, etc
after that when then tell GLUT to enter the fullscreen mode which it callse Game Mode.
we do this with:
glutEnterGameMode();
then when we want to exit the program we say:
glutLeaveGameMode(); to set the screen back to how it was

and that was it. simple wasn’t it?

If you have any questions, just email me at swiftless@gmail.com :-)

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
  #include <GL/gl.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <math.h>

//angle of rotation
float xpos = 0, ypos = 0, zpos = 0, xrot = 0, yrot = 90, angle=0.0;

//draw the cubes, they make a fancy shape from above :P
void cube (void) {
    float i;
    for (i=0;i<50;i++)
    {
    glTranslated(1, 0, 1);
    glPushMatrix();
    glutSolidCube(2); //draw the cube
    glPopMatrix();
    }
}

void init (void) {
    glEnable (GL_DEPTH_TEST); //enable the depth testing
    glEnable (GL_LIGHTING); //enable the lighting
    glEnable (GL_LIGHT0); //enable LIGHT0, our Diffuse Light
    glShadeModel (GL_SMOOTH); //set the shader to smooth shader

}

void camera (void) {
    glRotatef(xrot,1.0,0.0,0.0);
    glRotatef(yrot,0.0,1.0,0.0);
    glTranslated(-xpos,-ypos,-zpos);
}

void display (void) {
    glClearColor (0.0,0.0,0.0,1.0); //clear the screen to 
black

    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /
/clear the color buffer and the depth buffer

    glLoadIdentity();  
    gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); /
/camera position, x,y,z, looking at x,y,z, Up Positions of the 
camera

    camera();
    cube(); //call the cube drawing function
    glutSwapBuffers(); //swap the buffers
    angle++; //increase the angle
}

void reshape (int w, int h) {
    glViewport (0, 0, (GLsizei)w, (GLsizei)h); //set the viewport
 to the current window specifications

    glMatrixMode (GL_PROJECTION); //set the matrix to projection

    glLoadIdentity ();
    gluPerspective (60, (GLfloat)w / (GLfloat)h, 1.0, 100.0); //set the perspective (angle of sight, width, height, , depth)
    glMatrixMode (GL_MODELVIEW); //set the matrix back to model

}

void keyboard (unsigned char key, int x, int y) {
    if (key==‘q’)
    {
    xrot += 1;
    if (xrot >360) xrot -= 360;
    }

    if (key==‘z’)
    {
    xrot -= 1;
    if (xrot < -360) xrot += 360;
    }

    if (key==‘w’)
    {
    float xrotrad, yrotrad;
    yrotrad = (yrot / 180 * 3.141592654f);
    xrotrad = (xrot / 180 * 3.141592654f);
    xpos += float(sin(yrotrad)) ;
    zpos -= float(cos(yrotrad)) ;
    ypos -= float(sin(xrotrad)) ;
    }

    if (key==‘s’)
    {
    float xrotrad, yrotrad;
    yrotrad = (yrot / 180 * 3.141592654f);
    xrotrad = (xrot / 180 * 3.141592654f);
    xpos -= float(sin(yrotrad));
    zpos += float(cos(yrotrad)) ;
    ypos += float(sin(xrotrad));
    }

    if (key==‘d’)
    {
    yrot += 1;
    if (yrot >360) yrot -= 360;
    }

    if (key==‘a’)
    {
    yrot -= 1;
    if (yrot < -360)yrot += 360;
    }
    if (key==27)
    {
    glutLeaveGameMode(); //set the resolution how it was
    exit(0); //quit the program
    }
}

int main (int argc, char **argv) {
    glutInit (&argc, argv);
    glutInitDisplayMode (GLUT_DOUBLE | GLUT_DEPTH); //set 
the display to Double buffer, with depth

    glutGameModeString( “1024×768:32@75); //the settings 
for fullscreen mode

    glutEnterGameMode(); //set glut to fullscreen using the 
settings in the line above

    init (); //call the init function
    glutDisplayFunc (display); //use the display function to 
draw everything

    glutIdleFunc (display); //update any variables in display,
 display can be changed to anyhing, as long as you move the 
variables to be updated, in this case, angle++;

    glutReshapeFunc (reshape); //reshape the window accordingly

    glutKeyboardFunc (keyboard); //check the keyboard
    glutMainLoop (); //call the main loop
    return 0;
}

VN:F [1.9.3_1094]
Please rate so I know where to improve the site. 1 means needs a lot of improvement, 10 means perfect. If you leave a low rating, please state why. I don't want people just coming to bash the site.
Rating: 8.4/10 (9 votes cast)
VN:F [1.9.3_1094]
Rating: +1 (from 1 vote)
19. OpenGL Fullscreen Mode, 8.4 out of 10 based on 9 ratings

Related posts:

  1. 23. OpenGL Camera Part 2
  2. 22. OpenGL Camera
  3. 24. OpenGL Camera Part 3
  4. 4. Terrain Triangle Strips
  5. 2. Terrain Loading

Comments (4)

Unrecognized game mode string error comes up.. :(

VA:F [1.9.3_1094]
Rating: 0.0/5 (0 votes cast)
VA:F [1.9.3_1094]
Rating: 0 (from 0 votes)

Hey Nishant,

Have you tried changing the game mode string, eg: “990×768:32@75″ to something that your monitor supports? This was done when I had my old CRT monitory and most LCD displays don’t use 75Hz.

Cheers,
Swiftless

VN:F [1.9.3_1094]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)

Seems like it’s not working for me.
I get the error
“Unrecognized game mode string word: 1200î800:32@60″

My game mode string is “1200×800:32@60″. what to do now? :O

Other than that, your tutorials are really really really awesome! Keep em coming!

VA:F [1.9.3_1094]
Rating: 5.0/5 (1 vote cast)
VA:F [1.9.3_1094]
Rating: 0 (from 0 votes)

Huum, been having a play around with this, though it dosent seem to want to go fullscreen with a single buffer, and when i use a double buffer it seems to stop my update calls.
glutIdleFunc (display); dosent seem to work, and as b4
glutPostRedisplay(); stops working with a double buffer.

VA:F [1.9.3_1094]
Rating: 5.0/5 (1 vote cast)
VA:F [1.9.3_1094]
Rating: 0 (from 0 votes)

Write a comment

Improve the web with Nofollow Reciprocity.