I want to learn OpenGL 4.4 on my PC under Windows 10, but I have a problem.
I have two graphics processors : the first is Intel HD Graphics 4000 wich is compatible with OpenGL 4.0
and the second is Nvidia NVS 5400M wich is compatible with OpenGL 4.6, but I could’nt create a window wich can render OpenGL 4.4 graphics
I first tried to use SDL for window creation with this code :
#include <iostream>
#include "SDL2/SDL.h"
using namespace std;
int main( int argc, char* *argv )
{
SDL_Init( SDL_INIT_VIDEO );
// We create the window
int pos = SDL_WINDOWPOS_CENTERED;
SDL_Window *window = SDL_CreateWindow( "OpenGL", pos, pos, 800, 600, SDL_WINDOW_OPENGL );
if( window == 0 )
{
cout << "Failed to create the window : " << SDL_GetError();
SDL_Quit();
return EXIT_FAILURE;
}
// We create the context to enable OpenGL rendering
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 4 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 4 );
SDL_GLContext context = SDL_GL_CreateContext( window );
if( context == 0 )
{
cout << "Failed to create an OpenGL context : " << SDL_GetError();
SDL_DestroyWindow( window )
SDL_Quit();
return EXIT_FAILURE;
}
SDL_Event *event = new SDL_Event;
bool again = true;
while( again )
{
SDL_WaitEvent( event );
if( event->type == SDL_WINDOWEVENT && event->window.event == SDL_WINDOWEVENT_CLOSE )
{
again = false;
}
else if( event->type == SDL_KEYDOWN && event->key.keysym.scancode == SDL_SCANCODE_ESCAPE )
{
again = false;
}
}
SDL_GL_DeleteContext( context );
SDL_DesteroyWindow( window );
SDL_Quit();
return EXIT_SUCCESS;
}
But the context creation fails with this error message :
Failed to create an OpenGL context : The operation is successful
( Very strange, doesn’t ? O_o )
Then I added this code before window creation to force SDL to use the second graphics processor :
const char* driver = SDL_GetVideoDriver( SDL_GetNumVideoDrivers() - 1 );
if( SDL_VideoInit( driver ) != 0 )
{
cout << "Failed to initialize the video module : " << SDL_GetError();
SDL_Quit();
return EXIT_FAILURE;
}
But it fails with this error message :
Failed to initialize the video module : dummy not available
So I tried using GLFW with this other code :
#include <iostream>
#include "GLFW/glfw3.h"
using namespace std;
int main( int argc, char* *argv )
{
glfwInit();
// We create the window
glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, 4 );
glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 4 );
glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );
GLFWwindow *window = glfwCreateWindow( 800, 600, "OpenGL", 0, 0 );
if( window == 0 )
{
cout << "Failed to create a window";
glfwTerminate();
return EXIT_FAILURE;
}
while( !glfwWindowShouldClose( window ) )
{
glfwPollEvents();
if( glfwGetKey( window, GLFW_KEY_ESCAPE )
{
glfwSetWindowShouldClose( window, 1 );
}
}
glfwDestroyWindow( window );
glfwTerminate();
return EXIT_SUCCESS;
}
But once again it fails.
And when I disable the Intel graphics processor in the Window’s device manager, the window creation is successful,
but the rendering is too slow
( the framerate is around 10 FPS in the demos that I downloaded against 150 when I don’t deactivate Intel ! )