I am learning opengl on my mac using both glfw and sfml and meet some hurdle on the OpenGL version.
When I run the code:
printf ("Renderer: %s\n", glGetString (GL_RENDERER));
printf ("OpenGL version supported: %s\n", glGetString (GL_VERSION));
printf("glsl: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
on glfw
Renderer: Intel(R) Iris(TM) Graphics 6100
OpenGL version supported: 4.1 INTEL-10.22.25
glsl: 4.10
on sfml
Renderer: Intel(R) Iris(TM) Graphics 6100
OpenGL version supported: 2.1 INTEL-10.22.25
glsl: 1.20
Is it my setting on the xcode project or that is the default framework setting? Is there a way I can change sfml to work with OpenGL 4.1 so that I get glsl 4.1 too?
glfw have this settings:
glfwWindowHint (GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, 1);
Do sfml have something similar?
With SFML you can specify the OpenGL version using sf::ContextSettings.
sf::ContextSettings settings;
settings.depthBits = 24;
settings.stencilBits = 8;
settings.majorVersion = 4;
settings.minorVersion = 1;
settings.attributeFlags = sf::ContextSettings::Default;
Then you pass it to the sf:Window as you create it:
sf::Window window(sf::VideoMode(800, 600), "OpenGL", sf::Style::Default, settings);
Bottom line is that SFML needs a backwards compatibility context. Because internally SFML relies on some legacy OpenGL functionality.
So if you aren't using SFML for anything SFML specific. Then I recommend continuing to use GLFW.
Related
I am trying to run an OpenGL code on WSL2 but am getting the following error on trying to run the executable:
GLFW error 65543: GLX: Failed to create context: GLXBadFBConfig
Unable to create GLFW window
This is the code I am using to create a window:
....
GLFWwindow* initialize() {
int glfwInitRes = glfwInit();
if (!glfwInitRes) {
fprintf(stderr, "Unable to initialize GLFW\n");
return nullptr;
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
GLFWwindow* window = glfwCreateWindow(1280, 720, "InitGL", nullptr, nullptr);
if (!window) {
fprintf(stderr, "Unable to create GLFW window\n");
glfwTerminate();
return nullptr;
}
glfwMakeContextCurrent(window);
....
return window;
}
....
GLFWwindow* window = initialize();
I am using VcxSrv as my X server.
Following is from the output for glxinfo
direct rendering: No (LIBGL_ALWAYS_INDIRECT set)
server glx vendor string: SGI
server glx version string: 1.4
client glx vendor string: Mesa Project and SGI
client glx version string: 1.4
GLX version: 1.4
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce 940MX/PCIe/SSE2
OpenGL version string: 1.4 (4.6.0 NVIDIA 457.30)
The following fix worked for me.
As #dratenik mentioned above, the problem persists because of direct rendering: No. To solve this, do the following:
In the bashrc/zshrc file, add the following:
export LIBGL_ALWAYS_INDIRECT=0
Or you could just remove export LIBGL_ALWAYS_INDIRECT=1 line from your bashrc/zshrc file if you have added it.
Then, start a new instance of VcxSrv with and unselect the Native opengl box on the Extra Settings page, and select the Disable access control box.
After doing this, direct rendering should be turned on, and you should get the following on running glxinfo:
direct rendering: Yes
server glx vendor string: SGI
server glx version string: 1.4
...
I am trying to develop simple OpenGL applications using the programmable pipeline, specifically using OpenGL 4.2+, but my programs seem to be stuck using OpenGL 3.0 and GLSL 1.30.
The output from glxinfo |grep "OpenGL" on my Ubuntu 18.04 machine is as follows:
OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) HD Graphics 520 (Skylake GT2)
OpenGL core profile version string: 4.5 (Core Profile) Mesa 18.0.5
OpenGL core profile shading language version string: 4.50
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 3.0 Mesa 18.0.5
OpenGL shading language version string: 1.30
OpenGL context flags: (none)
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.2 Mesa 18.0.5
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
OpenGL ES profile extensions:
I've created a simple program which I believe should initialise an OpenGL 4.2 context:
#include <iostream>
#include <string>
#include <GL/glew.h>
#include <GL/freeglut.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
using namespace std;
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(600, 600);
glutCreateWindow("OpenGL Test");
glutInitContextVersion (4, 2);
glutInitContextProfile (GLUT_CORE_PROFILE);
if(glewInit() == GLEW_OK)
{
cout << "GLEW initialization successful! " << endl;
cout << "Using GLEW version " << glewGetString(GLEW_VERSION) <<
endl;
}
else
{
cerr << "Unable to initialize GLEW ...exiting." << endl;
exit(EXIT_FAILURE);
}
cout << glGetString(GL_VERSION) << endl;
cout << glGetString(GL_SHADING_LANGUAGE_VERSION) << endl;
}
However, when I run this program the following output is printed to the console, showing the the OpenGL version used is 3.0 and the GLSL version used is 1.3.
GLEW initialization successful!
Using GLEW version 2.0.0
3.0 Mesa 18.0.5 # OpenGL version
1.30 # GLSL Version
I am compiling and running my program as follows:
g++ OpenGLTest.cpp -o OpenGLTest -lglut -lGLU -lGL -lGLEW
./OpenGLTest
What I am doing wrong or what else could I try to fix this?
glutInitContextVersion and such sets parameters to be used for next context creation; all contexts that are already created will not be affected. That is true for many libraries, not just freeglut (e.g. SDL behaves the same way). As far as I can tell there is no dedicated function to create contexts in GLUT - context is created as part of window creation, so you need to set your parameters before calling glutCreateWindow.
I would like to replicate tutorials (sprite rendering), that use OpenGL version >= 3.3.
Geometry shaders for example were introduced in 3.2, and I get this error:
error: ‘GL_GEOMETRY_SHADER’ was not declared in this scope
I updated my mesa driver to the latest; I don't really understand though, how I can choose a newer version of OpenGL when compiling/linking in c++:
➜ glxinfo | grep -i "version"
server glx version string: 1.4
client glx version string: 1.4
GLX version: 1.4
Version: 17.1.4
Max core profile version: 4.5
Max compat profile version: 3.0
Max GLES1 profile version: 1.1
Max GLES[23] profile version: 3.1
OpenGL core profile version string: 4.5 (Core Profile) Mesa 17.1.4
OpenGL core profile shading language version string: 4.50
OpenGL version string: 3.0 Mesa 17.1.4
OpenGL shading language version string: 1.30
OpenGL ES profile version string: OpenGL ES 3.1 Mesa 17.1.4
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.10
I cannot really interpret this, but it says there is some kind of core profile using version 4.5. How do I utilize this profile?
I initialize the GL context in my code like this:
if(!glfwInit()) e_glfw_init();
m_window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE.c_str(), nullptr, nullptr);
if(m_window == nullptr) e_window_context();
glfwMakeContextCurrent(m_window);
glewExperimental = true;
if(glewInit() != GLEW_OK) e_glew_init();
According to the glfw documentation, you can specify the OpenGL version and profile by using the glfwWindowHint function:
if(!glfwInit()) e_glfw_init();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
m_window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE.c_str(),
nullptr, nullptr);
I had solved this issue on Linux by including these three headers when while playing with GLFW and shaders:
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>
I'm trying to create a glfw window in my Debian Stretch system.
The code for initialize glfw:
// Initialize GLFW
void initGLFW()
{
if (!glfwInit())
{
exit(EXIT_FAILURE);
}
glfwSetErrorCallback(errorCallback);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_FALSE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "GLSL4.3 + GLM + VBO + VAO", NULL, NULL);
if (!window)
{
fprintf(stderr, "Failed to open GLFW window.\n");
glfwTerminate();
//system("pause");
exit(EXIT_FAILURE);
}
}
When I run the executable I get the messages above. Why?
GLX: Failed to create context: GLXBadFBConfig
Failed to open GLFW window.
Running with LIBGL_DEBUG=verbose I get this
libGL: Can't open configuration file /home/rafael/.drirc: No such file or directory.
libGL: pci id for fd 5: 8086:0a16, driver i965
libGL: OpenDriver: trying /usr/lib/x86_64-linux-gnu/dri/tls/i965_dri.so
libGL: OpenDriver: trying /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
libGL: Can't open configuration file /home/rafael/.drirc: No such file or directory.
libGL: Using DRI3 for screen 0
Some useful infos:
$ lspci | grep VGA
00:02.0 VGA compatible controller: Intel Corporation Haswell-ULT Integrated Graphics Controller (rev 0b)
$ glxinfo | grep version
server glx version string: 1.4
client glx version string: 1.4
GLX version: 1.4
Max core profile version: 3.3
Max compat profile version: 3.0
Max GLES1 profile version: 1.1
Max GLES[23] profile version: 3.0
OpenGL core profile version string: 3.3 (Core Profile) Mesa 11.2.2
OpenGL core profile shading language version string: 3.30
OpenGL version string: 3.0 Mesa 11.2.2
OpenGL shading language version string: 1.30
OpenGL ES profile version string: OpenGL ES 3.0 Mesa 11.2.2
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.00
The initGLFW function is the first function called from main.
You are trying to create an OpenGL 4.0 Core profile context:
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
Your driver/OpenGL implementation only supports up to 3.3:
OpenGL core profile version string: 3.3 (Core Profile) Mesa 11.2.2
Max core profile version: 3.3
Mesa 11.2.2 could support OpenGL 4.1 but only on certain drivers (from the release notes of 11.0.0):
OpenGL 4.1 on radeonsi, nvc0
Mesa 12.0.0 seems to support OpenGL 4.3 on i965:
OpenGL 4.3 on nvc0, radeonsi, i965 (Gen8+)
The fix would be to update your graphics card, Mesa3D or to create a 3.3 context instead:
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
I am running Arch Linux with Mesa 10 on an HP laptop with an Intel HD 3000 GPU. (There is also an ATI card but I shut it off at boot.) I am trying to run OpenGL code with the core profile. OpenGL 3.1 and GLSL 1.4 should be supported according to glxinfo:
-> % glxinfo | grep version
OpenGL core profile version string: 3.1 (Core Profile) Mesa 10.0.1
OpenGL core profile shading language version string: 1.40
OpenGL version string: 3.0 Mesa 10.0.1
OpenGL shading language version string: 1.3
However, when I compile a GLFW program, try to force the core profile, and ask for the OpenGL version like so:
#include <GL/glew.h>
#include <GLFW/glfw3.h>
int main(void)
{
// Use OpenGL 3.1 core profile
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
glfwWindowHint(GLFW_CONTEXT_REVISION, 0);
// Create opengl context
int window_width = 1024;
int window_height = 768;
GLFWwindow* window = initialize_glfw(window_width, window_height);
if (!window)
{
glfwTerminate();
std::exit(EXIT_FAILURE);
}
// Display OpenGL version
int major, minor, rev, client, forward, profile;
glfwGetVersion(&major, &minor, &rev);
std::cout << "OpenGL - " << major << "." << minor << "." << rev << std::endl;
}
as well as compile shaders with GLSL #version 140, this is the printed output:
-> % ./main
OpenGL - 3.0.3
Shader compilation failed with this message:
0:1(10): error: GLSL 1.40 is not supported. Supported versions are: 1.10, 1.20, 1.30, 1.00 ES, and 3.00 ES
So, it seems like OpenGL 3.1 and GLSL 1.4 should be supported, but they are not being used in my GLFW program. Can anyone tell me what might be wrong?
After re-reading the documentation, there seem to have been two problems. One, as elmindreda pointed out, is that calling init after making window hints sets the window hints back to their defaults, so init must be called first.
Second, I am using OpenGL 3.1, and the GLFW docs say "If requesting an OpenGL version below 3.2, GLFW_OPENGL_ANY_PROFILE must be used." I was trying to use GLFW_OPENGL_CORE_PROFILE.
You need to initialize GLFW before calling other functions. You also need to make the OpenGL context current before calling functions on it.