I can't open an OpenGL window, due to following error message (I'm on Windows):
GLFW Error Code 65543: WGL: OpenGL profile requested but WGL_ARB_create_context_profile is unavailable.
It is likely that my problem is a driver problem. I tried to update them (using Intel Driver Update Utility), but it didn't do the trick (and my driver seemed to be already up to date). I use built-in Intel HD Graphics 3000. I also installed a OpenGL viewer, which tells me that my OpenGL version is 3.1).
Also, I tried this solution.
The whole C++ code is quite huge so I won't copy it all , but here is the interesting part:
if( !glfwInit() )
{
std::cerr<<"Failed to initialize GLFW\n"<<std::endl;
return -1;
}
glfwSetErrorCallback(glfwErrorCallback);
// Create the OpenGL window
glfwWindowHint(GLFW_DEPTH_BITS, 16);
glfwWindowHint(GLFW_SAMPLES, 4);
//Those stop GLFW from initializing successfully?
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// Open OpenGL fullscreen window
gGLFWWindow = glfwCreateWindow(gWidth,gHeight,"GLFW OpenGL Window",nullptr,nullptr);
if(!gGLFWWindow)
{
std::cerr<<"Failed to open GLFW window\n"<<std::endl;
glfwTerminate();
return -1;
}
// Disable VSync (we want to get as high FPS as possible!)
glfwMakeContextCurrent(gGLFWWindow);
glfwSwapInterval( 1 );
// Setting this is necessary for core profile (tested with MSVC 2013 x64, Windows 7)
glewExperimental = GL_TRUE;
// GLEW wraps all OpenGL functions and extensions
GLenum err = glewInit();
if(err != GLEW_OK)
{
std::cerr<<"Failed to initialize GLEW"<<std::endl;
std::cerr<<(char*)glewGetErrorString(err)<<std::endl;
glfwTerminate();
return -1;
}
glGetError(); //GLEW might cause an 'invalid enum' error, safely ignore it?
// Print OpenGL context information to console
ogl::printContextInformation();
// Perform our initialization (OpenGL states, shader, camera, geometry)
if(!init())
return -1;
It fails at this line :
gGLFWWindow = glfwCreateWindow(gWidth,gHeight,"GLFW OpenGL Window",nullptr,nullptr);
Does anyone have an idea of what I could do to solve this issue?
The answer is : I was requesting a Core 3.3 context whereas my version was OpenGL 3.1.
Deleting/commenting those lines will do the trick :
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
I to had the same problem because my last machine has an openGl of version 3.3 and now because the one am using now has but an openGl 3.1 made me almost got frustrated
But De-comenting the "window hints", it solves the problem
Related
I'm trying to use OpenGL with GLEW and GLFW. However, it appears that I cannot call glewInit() successfully and I get the following error message: GLEW error (1): Missing GL version. Similar questions at Stackoverflow haven't solved my problem.
When building my project, I am including the glew.c file and the directory where glew.h is.
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <iostream>
int main()
{
glfwInit();
glfwWindowHint(GLFW_SAMPLES, 0);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "Testing", nullptr, nullptr);
glfwMakeContextCurrent(window);
glewExperimental = true;
GLenum glewErr = glewInit();
if (glewErr != GLEW_OK)
{
std::cerr << "GLEW error (" << glewErr << "): " << glewGetErrorString(glewErr) << std::endl;
glfwTerminate();
return -1;
}
// Next, I paint some stuff using OpenGL ...
}
Everything looks ok in the code. Furthermore, for some reason, if I use GLAD instead of GLEW, my code works just fine.
System: Ubuntu 18.04.5 LTS.
OGL version: 3.3.0 NVIDIA 340.108
OGL vendor: NVIDIA Corporation
Renderer: GeForce 820M/PCIe/SSE2
GLSL version: 3.30 NVIDIA via Cg compiler
UPDATE:
Diving deep into glew.c code I found where the error pops up, though I can't still understand why. Here it is the piece of code
static GLenum GLEWAPIENTRY glewContextInit ()
{
PFNGLGETSTRINGPROC getString;
const GLubyte* s;
GLuint dot;
#ifdef _WIN32
getString = glGetString; // Not executed, I'm on Ubuntu
#else
getString = (PFNGLGETSTRINGPROC) glewGetProcAddress((const GLubyte*)"glGetString");
if (!getString)
return GLEW_ERROR_NO_GL_VERSION;
#endif
/* query opengl version */
s = getString(GL_VERSION); // <<< ERROR: s gets a null pointer
dot = _glewStrCLen(s, '.');
if (dot == 0)
return GLEW_ERROR_NO_GL_VERSION; // <<< Function escapes here
// ... more statement down here
}
There is something strange happening with gl3w's isSupported function. When I call isSupported(4, 0) it returns false, meaning OpenGL 4.0 isn't supported. However, when I call glGetString(GL_VERSION) it says OpenGL version 4.0.
Does this mean I can use OpenGL 4.0 functions?
I'm using gl3w in C++ and Visual Studio 2017
#include <GL/gl3w.h>
#include <GLFW/glfw3.h>
int main(int argc, char** argv){
if(!glfwInit()) {
FATAL_ERROR("Failed to initialise GLFW");
}
glfwSetErrorCallback(glfwErrorCallback);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
GLFWwindow* window = glfwCreateWindow(640, 480, "OpenGL", nullptr, nullptr);
//If i put glfwMakeContextCurrent here gl3wInit fails
//glfwMakeContextCurrent(window);
if (!window) {
glfwTerminate();
FATAL_ERROR("Window creation failed");
}
if(!gl3wInit()) {} // handle that
glfwMakeContextCurrent(window);
bool support = gl3wIsSupported(4, 0); // returns false
const char* version = glGetString(GL_VERSION); // return "4.0.0"
}
You have to make a GL context current before you call gl3wInit() or regular OpenGL functions otherwise they won't do anything useful.
In the OpenGL wiki you can read:
The GL3W library focuses on the core profile of OpenGL 3 and 4. It
only loads the core entrypoints for these OpenGL versions. It supports
Windows, Mac OS X, Linux, and FreeBSD.
Note: GL3W loads core OpenGL
only by default. All OpenGL extensions will be loaded if the --ext
flag is specified to gl3w_gen.py.
And this is confirmed looking inside the code:
int gl3wIsSupported(int major, int minor)
{
if (major < 3) // <<<<=========== SEE THIS
return 0;
if (version.major == major)
return version.minor >= minor;
return version.major >= major;
}
You are asking with glfwWindowHint for an old 2.0 version. Thus, gl3wIsSupported will return false and gl3wInit will return GL3W_ERROR_OPENGL_VERSION.
For glGetString(GL_VERSION) returning "4.0" means that, yes, you can use that 4.0 version. Ask for it with glfwWindowHint.
I fixed it by switching over to glad instead
if (!glfwInit()) {
FATAL_ERROR("Failed to initialise GLFW");
}
glfwSetErrorCallback(glfwErrorCallback);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
GLFWwindow* window = glfwCreateWindow(640, 480, "OpenGL", nullptr, nullptr);
if (!window) {
glfwTerminate();
FATAL_ERROR("Window creation failed");
}
glfwMakeContextCurrent(window);
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
glfwDestroyWindow(window);
glfwTerminate();
FATAL_ERROR("Failed to initialise OpenGL context");
}
PRINT("OpenGL Version: " << GLVersion.major << "." << GLVersion.minor);
I have the following code:
void error_callback(int error, const char* description)
{
fputs(description, stderr);
}
int main( void )
{
// Initialise GLFW
if( !glfwInit() )
{
fprintf( stderr, "Failed to initialize GLFW\n" );
return -1;
}
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
//glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// Open a window and create its OpenGL context
glfwSetErrorCallback(error_callback);
window = glfwCreateWindow( 1024, 768, "Tutorial 16 - Shadows", NULL, NULL);
if( window == NULL ){
//fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
// Initialize GLEW
GLenum err;
glewExperimental = GL_TRUE; // Needed for core profile
if ((err = glewInit()) != GLEW_OK) {
std::cout << glewGetErrorString(err) << std::endl;
return -1;
}
...
}
The problem is that I'm receiving the following message: https://github.com/glfw/glfw/blob/master/src/nsgl_context.m#L101
And, indeed, GLFW won't give me a OpenGL 3+ context without setting the forward-compatibility flag (in Mac OS X).
Why is that? Is there any way to get a OpenGL 3+ context in Mac OS X 10.9 without forward-compatibility? Is it a limitation of OpenGL implementation for OS X or a problem of GLFW?
This is actually the correct behavior, as defined in the OpenGL Programming Guide for Mac.
Mac OS X simply does not support the compatibility profile for OpenGL 3.x/4.x, so you must request a core (or forward-compatible) context. This implies that you will not be able to use any deprecated functions when programming against OpenGL 3.x/4.x on a Mac.
It might be worth to make a feature request in the GLFW issue tracker to set the core profile flag implicitly when requesting a 3.x/4.x context on Mac OS X.
I have started work on a new project with OpenGL 3.3. I was using GLFW and GLEW for window setup and loading of GL functions, but switched to the Unofficial OpenGL SDK instead of GLEW. The problem remained, though:
I was getting a segmentation fault when calling glCreateShader(G_VERTEX_SHADER), and it turned out, that the function pointer was NULL. I later found out that it was caused by an invalid GL Context.
This is the setup code:
#include <glload/gl_3_3.h>
#include <glload/gll.h>
#include <GL/glfw.h>
#include <glm.hpp>
#include <gtc/matrix_transform.hpp>
#include "Cube.h"
template <class T>
int arraySize(T *a) {
return (sizeof(a) / sizeof(*a));
}
int main() {
if(!glfwInit()) {
fprintf(stderr, "Failed to initialize GLFW\n");
return -1;
}
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
// Open a window and create its OpenGL context
if(!glfwOpenWindow(1024, 768, 0,0,0,0, 0,0, GLFW_WINDOW)) {
fprintf(stderr, "Failed to open GLFW window\n");
glfwTerminate();
return -1;
}
if(LoadFunctions() == LS_LOAD_FAILED) {
fprintf(stderr, "Failed to load GL functions.\n");
return -1;
}
I have searched for answers on Google, and on here, but haven't been able to find anything. I also asked in the OpenGL IRC channel on Freenode, and they told me to try the Unofficial SDK instead of GLEW, because GLEW with the core profile is bad. This didn't work, though.
The most weird thing is, that it worked previously, with the exact same setup as now.
By the way, I am using Windows 7 x64 with the newest available drivers.
SOLUTION:
I was being dumb, and calling glCreateShader() before glewInit(). Sorry for being dumb :(
I am sure that everything is linked correcly. I initially was using glload and glfw from the Unofficial GLSDK but then I decided to do away with glload which meant that I had to use glew in order to get at the modern headers.
#include <GL/glew.h>
#include <GL/glfw.h>
I have included glew before glfw as per the instructions.
During run time the OpenGL window opens
//(relevant code)
if(!glewInit()) {return -1; }
if(!glfwInit()) {return -1; }
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// also tried glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);
if(!glfwOpenWindow(1024, 768, 8, 8, 8, 8, 24, 8, GLFW_WINDOW)){
glfwTerminate();
return -1;
}
glfwSetWindowTitle("OpenGL 3.2");
//init method
glGenVertexArrays(1, &vao); //<< Access violation here.
Any ideas what my problem is here?
I have looked at. "Access violation using VBO with glew" But it was no help.
glewInit is to be called after a OpenGL context has been created and bound to the current thread, i.e. after glfwOpenWindow in your case.
A little late, but figured I'd pipe in anyways.
As mentioned by datenwolf, in your relevant code posted the glewInit() should return an error due to it's positioning.
The other potential issue you could be encountering is described on http://www.opengl.org/wiki/OpenGL_Loading_Library under the GLEW section.
copy-paste from above:
GLEW has a problem with core contexts.
It calls glGetString(GL_EXTENSIONS),
which causes GL_INVALID_ENUM on GL 3.2+ core context as soon as glewInit() is called.
Solution for GLEW (also provided by above link) is to enable 'EXPERIMENTAL' support. Ex:
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if( err != GLEW_OK )
{
printf("GlewInit error");
exit(1);
}
Also late but for anyone still looking
glewExperimental = GL_TRUE;
Before initializing the context was got rid of the access violation error, but instead made the program exit with a GL_INVALID_ENUM error. With GLFW, I had to additionally comment out the window hints:
//glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
//glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
//glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
//glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);
The programs then started compiling!