GLFW window creation options affecting the HarfBuzz - opengl

I am using HarfBuzz along with freetype to render regional language hindi.
If I write these three optins for window creation than the font does not render and I only see the blank screen.
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
Without these three options the font renders correctly.
I am curious to know what difference these options make in window creation?

That is because you create a core profile OpenGL Context (GLFW_OPENGL_CORE_PROFILE).
In compare to a compatibility profile context (GLFW_OPENGL_COMPAT_PROFILE), which is default, Legacy OpenGL OpenGL instructions are not valid and cause OpenGL errors.
The main difference is, that you can't use glBegin/glEnd sequences, fixed function attributes (e.g. glVertexPointer) respectively client-side capability or the current matrix stack.
If you want to draw geometry, then you've to create Vertex Array Objects and to use Shader programs.
The complete differences can be seen in the OpenGL 3.3 Compatibility Profile specification or for the most recent OpenGL version OpenGL 4.6 API Compatibility Profile Specification, where the functionality that is only in the compatibility profile specification and not in the core specification is typeset in orange.

Related

Unable to compile vertex shader in Maya Plugin

I am writing a plugin on Maya/MacOS which is compiling a vertex shader for OpenGL:
const char* vscode =
{
"#version 150\n"
...
}
However executing the code in Maya gives me
ERROR: 0:1: '' : version '150' is not supported
The OpenGL version returned is 2.1 ATI-1.42.6. I tried to change the OpenGL via glut
glutInitDisplayMode(GLUT_3_2_CORE_PROFILE);
But it does not seem to change the OpenGL Core Profile. How can I change the core profile from within a Maya plugin, or how can I know which "xxx" version would be supported in the shader ?
The OpenGL version returned is 2.1 ATI-1.42.6. I tried to change the OpenGL via glut
Does Maya use GLUT? No! So how so you expect this to work then?
GLUT is a independent library that does window and OpenGL context creation. GLUT is not part of OpenGL and GLUT can not influence OpenGL context management of programs not using GLUT.
Maya does its OpenGL context management internally and when your plugin is called a OpenGL context is already created and the version profile of that particular context set into stone.
But what you can do is you can create a very own OpenGL context, just for your plugin and connect it with the OpenGL context that Maya created (OpenGL context sharing). Doing this is advisable anyway, since this separates OpenGL your plugin uses from OpenGL state Maya uses.
You will have to use the system level OpenGL context management APIs for that. So no GLUT, no GLFW, no SMFL or other helper libraries. Don't worry, it's not too difficult to do. Regarding connecting with the OpenGL context of Maya, every OpenGL context management API has functions to query the currently active OpenGL context and the drawable it's active on. Use those to store which context+drawable pair was active before your plugin got called, then before returning to Maya reset the OpenGL context activation to that pair.

Can't draw with opengl version greater then 3.1 with SDL

I'm making a simple application using OpenGL, GLEW and SDL2 which draws a simple quad on screen (I'm following the example on lazyfoo site with modern OpenGL).
When I use opengl version 3.1 everything works fine, but if I use OpenGL version 3.2+ draw commands don't work (triangle doesn't appear). Does someone know what I am doing wrong?
This is how I setup everything:
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
return false;
}
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
m_pWindow = SDL_CreateWindow("Hello World!", 100, 100, 800, 600, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN );
m_pGLContext = SDL_GL_CreateContext(m_pWindow);
glewExperimental = GL_TRUE;
GLenum glewError = glewInit();
if (glewError != GLEW_OK)
{
return false;
}
//Use Vsync
if (SDL_GL_SetSwapInterval(1) < 0)
{
return false;
}
If you want to check it grab one-file cpp source from http://lazyfoo.net/tutorials/SDL/51_SDL_and_modern_opengl/index.php (on site bottom), and try to change version of opengl from 3.1 to 3.2.
In OpenGL 3.2, the OpenGL profiles were introduced. The core profile actually removes all of the deprecated functions, which breaks compaitibily with older GL functions. The compatibility profile retains backwards compatibility.
To create "modern" OpenGL context, the extensions like GLX_create_context (Unix/X11) or WGL_create_context (Windows) have to be used (and SDL does that for you internally). Citing these extensions specifications gives the answer to your question:
The attribute name GLX_CONTEXT_PROFILE_MASK_ARB requests an OpenGL
context supporting a specific profile of the API. If the
GLX_CONTEXT_CORE_PROFILE_BIT_ARB bit is set in the attribute value,
then a context implementing the core profile of OpenGL is
returned. If the GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB bit is
set, then a context implementing the compatibility profile is
returned. If the requested OpenGL version is less than 3.2,
GLX_CONTEXT_PROFILE_MASK_ARB is ignored and the functionality of the
context is determined solely by the requested version.
[...]
The default value for GLX_CONTEXT_PROFILE_MASK_ARB is
GLX_CONTEXT_CORE_PROFILE_BIT_ARB. All OpenGL 3.2 implementations are
required to implement the core profile, but implementation of the
compatibility profile is optional.
SInce you did not explicitely request a compatibility profile (and SDL does neither), you got a core profile, and it seems like your code is invalid in a core profile.
You might try requesting a compaitbility profile by adding the
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
hint before creating the context.
But be warned that this is not universally supported - MacOS generally supports only GL up to 2.1 OR GL >= 3.2 core profile only. THe open source drivers on Linux only support OpenGL >= 3.2 only in core profile, too. So my recommendation is that you actually fix your code and switch to a core profile.

OpenGL ES 2.0 with osmesa

I am attempting to create an OpenGL context with osmesa (off-screen mesa). I wish to use the software implementation of mesa without a window and save the rendered output to a png file.
http://www.mesa3d.org/osmesa.html
I create a GL context with the following:
OSMesaContext context = OSMesaCreateContext(GL_RGBA, NULL);
OSMesaMakeCurrent(context, buffer, GL_UNSIGNED_BYTE, width, height);
However, when I invoke glGetString(GL_VERSION) the version is 2.1 Mesa 10.1.1. As expected, none of my GLSL ES shaders compile. When using SDL I can supply a version hint and create a GLES 2.0 context.
How do I specify the version of the GL context being created by osmesa?
If you look at src/mesa/drivers/osmesa/osmesa.c, around line 745, you can see that it explicitly asks for an OpenGL compatibility profile, which Mesa limits to OpenGL 2.1 and GLSL 130 (see src/mesa/main/version.c line . Replacing API_OPENGL_COMPAT with API_OPENGL_CORE results with the OpenGL version being 0.0 in Mesa 10.6.2, so unfortunately, the simple fix doesn't work. But, setting the MESA_GL_VERSION_OVERRIDE environment variable to "3.3" appears to work. Haven't tested beyond seeing what glGetString(GL_VERSION) returns. Good luck!

GLFW can't create 4.3 context

I've begun using OpenGL via C++ and GLFW, but calls to glfwCreateWindow(...) aren't creating a context using the latest version of OpenGL available on my system (currently 4.3).
I've used OpenGL 4.3 contexts before with Java and LWJGL, but since switching to GLFW I've been unsuccessful.
Adding calls to
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
causes glfwCreateWindow(...) to return an error code, though changing the minor version to 2 works fine. Adding window hints to use a core profile and setting forward-compatibility to true also have no effect.
Does anyone know what the cause of it might be/a solution to this problem?
Edit: This is on Windows 7.
Do this:
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // yes, 3 and 2!!!
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
And you can use OpenGL 4.x anyways...
Why?
Check the FAQ -- "4.1 - How do I create an OpenGL 3.0+ context?"

Can I mix OpenGL versions?

I'm going to start implementing OpenGL 3 into my application. I currently am using OpenGL 1.1 but I wanted to keep some of it due to problems if I attempt to change the code but I wanted to change some of my drawing code to a faster version of OpenGL. If I do things like bind textures in OpenGL 1.1 can I draw the texture in OpenGL 3?
Mixing OpenGL versions isn't as easy as it used to be. In OpenGL 3.0, a lot of the old features were marked as "deprecated" and were removed in 3.1. However, since OpenGL 3.2, there are two profiles defined: Core and Compatibility. The OpenGL context is created with respect to such a profile. In compatibility profile,
all the deprecated (and in core profiles removed) stuff is still availbale, and it can be mixed as well. You can even mix a custom vertex shader with the fixed-function fragment processing or vice versa.
The problem here is that it is not grequired that implementors actually provide support for the compatibility profile. On MacOS X, OpenGL 3.x and 4.x are supported in core profile only.
In you specific example, binding textures will work in all cases, since that funtctionality exists unmodified in all versions from 1.1 to 4.3 (and is likely to do so in the near future). However, most of your drawing calls are likely to be not available in the newer core profiles.
Omg.. opengl 1.1 is from 1997! Do yourself a favor and get rid of the fixed-function pipeline stuff and adapt to OpenGL 4.x. However, you can try
#version 420 core
in your shader.