Glew initialisation failed : Missing GL version (GLFW) - c++

I'm currently trying to draw a simple triangle with GLFW and GLEW.
I'm using CLion (which is itself using cmake with cygwin) on a Win 8.1 x64 PC.
My problem is : glewInit() returns error 1 (Missing GL version) when initialized. People (like in this thread) had a problem related to the OpenGL context, but mine is already created before I call glewInit().
Here is my code :
#include <iostream>
#include <stdlib.h>
#include <vector>
#define GLEW_STATIC
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
//...
if(!glfwInit()) {
std::cerr << "Couldn't initialize GLFW" << std::endl;
}
glfwSetErrorCallback(glfw_error_callback);
glfwWindowHint(GLFW_SAMPLES, 4); //16x antialiasing sisi rpz
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // OpenGL 3.3
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
window = glfwCreateWindow(width, height, title.c_str(), NULL, NULL);
if(window == NULL) {
std::cerr << "Failed to open GLFW window. Are your drivers up-to-date ?" << std::endl;
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window);
if(!glfwGetCurrentContext()) {
std::cerr << "Couldn't create OpenGL context" << std::endl;
exit(EXIT_FAILURE);
}
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if(err != GLEW_OK) {
std::cerr << "Failed to initialize glew : " << glewGetErrorString(err) << " (" << err << ")" << std::endl;
}
and my CMakeLists.txt :
cmake_minimum_required(VERSION 2.8.4)
project(MY_PROJECT)
set(SOURCE_FILES main.cpp Host.cpp GraphicWindow.cpp)
add_executable(MY_PROJECT ${SOURCE_FILES})
target_link_libraries(MY_PROJECT wsock32 ws2_32)
#GL stuff
include_directories(lib/glew-1.11.0/include/)
include_directories(lib/glfw-3.0.4.bin.WIN64/include/)
include_directories(lib/glm)
target_link_libraries(MY_PROJECT glfw3 glu32 gdi32 opengl32 glew)

Related

GLFW error #65544 "Failed to initialize GLFW"

here's my code:
#include <iostream>
#include <GLFW/glfw3.h>
int main(void){
GLFWwindow* window;
if(!glfwInit()){
std::cout << "Failed to initialize GLFW!" << std::endl;
return -1;
}
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if(!window){
glfwTerminate();
std:: cout << "Failed to initialize Window!" << std::endl;
return -1;
}
glfwMakeContextCurrent(window);
while(!glfwWindowShouldClose(window)){
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
I successfully linked it and compile, but I'm having a runtime error
it says that glfw failed to initialize.I tried to use glfw in C but this error shows
Wayland: Failed to connect to display
The GLFW library is not initialized
main: ./src/posix_thread.c:64: _glfwPlatformGetTls: Assertion `tls->posix.allocated == GLFW_TRUE' failed.
Aborted (core dumped)
. I'm using popOS 22.04 LTS, I'm new to c++ and glfw pls help me fix this problem

Failed glewInit: Missing GL version

I began to study OpenGL on the course.Download glew-2.1.0(64) and glfw-3.2.1(64). Like everything connected and IDE not swear but initialization produces the following output in the command line:
Error initialization GLEW: Missing GL version
#include <iostream>
#define GLEW_STATIC
#include <GL/glew.h>
// GLFW
#include <GLFW/glfw3.h>
const char* APP_TITLE = "Introduction in modern openGL";
const int gWindowWidth = 800;
const int gWindowHeight = 600;
int main()
{
if (!glfwInit())
{
std::cerr << "Failed in initialization GLFW" << std::endl;
return -1;
}
glfwWindowHint(GLFW_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* pWindow = glfwCreateWindow(gWindowWidth, gWindowHeight, APP_TITLE, NULL, NULL);
if (pWindow)
{
std::cerr << "Failed in create Windows" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(pWindow);
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (GLEW_OK != err)
{
std::cerr << "Error initialization GLEW: " << glewGetErrorString(err) << std::endl;
glfwTerminate();
return -1;
}
while (!glfwWindowShouldClose(pWindow))
{
glfwPollEvents();
glfwSwapBuffers(pWindow);
}
glfwTerminate();
return 0;
}
What is the problem? I searched on the Internet, but there are solutions to problems of the type:
add glfwMakeContextCurrent(game_window); before glewInit()
Very stupid mistake
I wrote
glfwWindowHint(GLFW_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_VERSION_MINOR, 3);
I should have
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);

glfw does not create a window

when i create a simple glfw window and set these two flags:
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
the window will be NULL and i have no idea why.
The window will be created if those two things are not called.
Here is the code Below:
#include <iostream>
using namespace std;
#include <GL/glew.h>
#include <GLFW/glfw3.h>
int main() {
if (!glfwInit()) {
cout << "glfw did not initialize!" << endl;
return -1;
}
glfwWindowHint(GL_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
//glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
//glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window;
window = glfwCreateWindow(640, 300, "ARoo", NULL, NULL);
if (!window) {
cout << "window == null" << endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
while (!glfwWindowShouldClose(window)) {
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
}
im using visual studi comunity 2015, windows 8.1 x64(glfw and glew are x32)
my video drivers are up to date.
The problem could be related to the requested OpenGL profile.
You can have diagnostic messages about what's happening, you just need to set a callback, which can be done before glfwInit():
static void glfwError(int id, const char* description)
{
std::cout << description << std::endl;
}
int main()
{
glfwSetErrorCallback(&glfwError);
glfwInit();
...

Enabling OpenGL 4.1 under OS X 10.10 with GLEW, GLFW and g++ compilation

I have a 2014 RMBP, updated to the latest version of OS X which should guarantee me compatibility up to OpenGL 4.1. I have put together a minimal working example:
#include <iostream>
#include "GL/glew.h"
#include <GLFW/glfw3.h>
using namespace std;
int main(){
int windowWidth = 800;
int windowHeight = 800;
string windowTitle = "title";
glfwDefaultWindowHints();
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
if( !glfwInit() )
{
cerr << "Failed to initialize GLFW.\n";
return 1;
} else {
clog << "Initialized GLFW." << endl;
}
GLFWwindow* pWindow = glfwCreateWindow(windowWidth, windowHeight, windowTitle.c_str(), 0, NULL);
glfwSetWindowPos(pWindow, 700, 200);
glfwMakeContextCurrent(pWindow);
if( pWindow == NULL )
{
cerr << "Failed to open GLFW window.\n";
glfwTerminate();
return 1;
}
std::cout << "GL Version: " << glGetString(GL_VERSION) << "\n";
std::cout << "GLSL Version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << "\n";
std::cout << "Vendor: " << glGetString(GL_VENDOR) << std::endl;
std::cout << "Renderer: " << glGetString(GL_RENDERER) << std::endl;
while (!glfwWindowShouldClose(pWindow))
{
glfwPollEvents();
}
glfwDestroyWindow(pWindow);
return 0;
}
This opens up a window which works fine, but it's outputting the following:
GL Version: 2.1 INTEL-10.0.86
GLSL Version: 1.20
Vendor: Intel Inc.
Renderer: Intel Iris OpenGL Engine
which is wrong! I should be getting 4.1 compatibility. I downloaded the examples at https://github.com/tomdalling/opengl-series and under xCode, it does go up to 4.1 so I know my computer is capable of it.
This is actually for a larger project; I did try importing my project into xcode, merging it with Tom Dalling's project, it just won't work, I always get GL 2.1.
I'm compiling the above code with
g++ main.cpp -o GLTEST -lglfw -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo \
... maybe I'm missing an option. Thank you so much for your help!
Reading about window creation hints at the glfw site, you'll find:
These hints are set to their default values each time the library is initialized with glfwInit
and Tom Dalling's (working) code calls glfwInit before hinting about the version while yours does it afterwards.
So I suspect that may have something to do with it.

Creating OpenGL 4.3 window fails with GLFW3

I set up a minimal application to open a blank window with GLFW3:
#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
void glfwErrorCallback(int error, const char *description)
{
std::cerr << "GLFW error " << error << ": " << description << std::endl;
}
int main(int argc, char **argv)
{
GLFWwindow* window;
glfwSetErrorCallback(glfwErrorCallback);
if(!glfwInit())
{
std::cerr << "Failed to initialize GLFW...\n";
return -1;
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
window = glfwCreateWindow(1024, 768, "GLFW window", NULL, NULL);
if(!window)
{
std::cerr << "Failed to open GLFW window...\n";
glfwTerminate();
return -1;
}
glewExperimental = GL_TRUE;
if (glewInit())
{
std::cerr << "Failed to initialize GLEW...\n";
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
while (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && !glfwWindowShouldClose(window))
{
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
It results in the following error:
GLFW error 65540: Context profiles only exist for OpenGL version 3.2 and above
Failed to open GLFW window...
The application is run on Linux with Bumblebee's optirun. The code works when using freeglut instead of GLFW. What is wrong with the code that results in the error?
This is pretty simple:
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); // Major = 4
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // Major was 4, now it is 3.
// Minor = ??? [Something < 2]
You need to use glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, 3); instead for the second hint.