Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Full screen in openGL

I am trying to render an openGL window in fullscreen and am using the NeHe tutorials to learn how to do this. however I have reached a point where I am using the exact same code in both the example code given and my own code, but when it reaches this line:

if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)

this doesn't evaluate to true in my code, even though it does in the example code given. this is even more confusing as while de-bugging everything was exactly the same up to this point.

Is there something simple I'm missing such as something in the project properties, or if not, could someone advise me on any other ways of creating a full screen window.

NeHe tutorial I am using: http://nehe.gamedev.net/tutorial/creating_an_opengl_window_%28win32%29/13001/

like image 751
Matt Avatar asked Dec 11 '22 16:12

Matt


1 Answers

If you're just learning, you could try using GLUT. You can create a window with it in a few lines, and you can just mess with your OpenGL code, until you're comfortable with it enough to actually try out platform specific APIs for doing so such as WinAPI.

You'll need to install Freeglut (implementation of the outdated GLUT), and GLEW (for the ease of using OpenGL 1.1+ functions because Microsoft's gl.h hasn't been updated since then)

Bare minimum code:

#define FREEGLUT_STATIC // defined so you can link to freeglut_static.lib when compiling
#define GLEW_STATIC     // defined so you can link to glew's static .lib when compiling

#include <GL/glew.h>     // has to be included before gl.h, or any header that includes gl.h
#include <GL/freeglut.h>

void draw()
{
    // code for rendering here
    glutSwapBuffers();   // swapping image buffer for double buffering
    glutPostRedisplay(); // redrawing. Omit this line if you don't want constant redraw
}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA); // enabling double buffering and RGBA
    glutInitWindowSize(600, 600);
    glutCreateWindow("OpenGL"); // creating the window
    glutFullScreen();           // making the window full screen
    glutDisplayFunc(draw);      // draw is your function for redrawing the screen

    glutMainLoop();

    return 0;
}
like image 56
Alex Avatar answered Dec 18 '22 03:12

Alex