Sign in to follow this  
Neosettler

OpenGL OpenGL for Linux and MacOSX?

Recommended Posts

Neosettler    150
Hello OpenGL gurus,

I’ve been developing with OpenGL exclusively on Windows for several years now and I’m entering the cross-platform compiling world.

So far, I use skaslev-gl3w [url="https://github.com/skaslev/gl3w"]https://github.com/skaslev/gl3w[/url] to generate gl3w.h, gl3.h and gl3w.c. I found OpenGL32.lib within Visual Studio… it’s a wonderful world indeed… but when compiling with g++ on Linux, gl3w.c is requesting glx.h… and cough at glXGetProcAddress... Oups! There is no trace of this file on opengl.org and Googling on this topic is rather confusing so I decide to ask here.

1 - Why GLX? I thought pure GL was king on Linux... I'm confuse! (I surely dont want to rewrite my code)

2 - Where to find the official OpenGL package to develop on Linux and MacOSX?

Thx Edited by Neosettler

Share this post


Link to post
Share on other sites
Bregma    9199
I can't answer about MaC OS X, it's been too many years for me. Linux isn't an OS so there's no definitive answer there, but I can tell you about Debian-derived OSes (like Ubuntu), which are GNU-based OSes that can sometimes use the Linux kernel: try installing the libgl1-mesa-dev package. If you're asking about Android, another common OS that uses the Linux kernel, the GLES libraries should come with your devkit.

The answer to why your third-party software (skaslev-gl3w) uses GLX, well, you'd have to ask whoever developed it, but it's a handy and standard way to create a GL context on an X11 server.

Share this post


Link to post
Share on other sites
Neosettler    150
Thank you Bregma,

Your answer almost gave me a heart attack. For all the porting a need to do, I thought OpenGL would be a breeze.

I’m currently working with CentOS/Redhat and I tried yum install libgl1-mesa-dev but the package is not found. So I’m guessing there’s extra steps to be made.

I simply need a pure OpenGL context 4.x, no extra lib, no fancy stuff, only the core… I’d really appreciate if anyone could help clear this up.

Thx again

Share this post


Link to post
Share on other sites
tglee    104
On CentOS/RHEL, you're probably after the [b]mesa-libGL-devel[/b] package. :)

http://rpm.pbone.net/index.php3/stat/4/idpl/17834939/dir/centos_5/com/mesa-libGL-devel-6.5.1-7.10.el5.i386.rpm.html

Share this post


Link to post
Share on other sites
Bregma    9199
[quote name='Neosettler' timestamp='1353619415' post='5003320']
I simply need a pure OpenGL context 4.x, no extra lib, no fancy stuff, only the core… I’d really appreciate if anyone could help clear this up.
[/quote]
Problems is there's not really such as thing as a pure OpenGL context. You're going to need [i]something[/i] to draw to.

Even if you're going full screen, you're not directly programming the GPU and you're not driving the video output chips, you need to go through the OS kernel. A typical modern OS kernel is design to prevent you from getting at the hardware directly: you need to ask it nicely at the very least if it will do you the favour of accessing the hardware on your behalf. On a GNU/Linux system, that means getting the X11 server to share nicely. On Mac OS X that means getting the Quartz service to share nicely. Even on Microsoft Windows you need to share nicely with other applications calling into the embedded display service. On Android you use EGL to share the flinger nicely.

There are cross-platform libraries that will get you an OpenGL context. That's what they're for and why they're there. SDL, for example, works very well on all the above platforms. If you insist on doing without such a library, the source is free so you can see how it works and reimplement it yourself. Of course, it might turn out SDL uses glx/wgl/egl underneath, because to do otherwise would reimplement all those ioctl/X11/port/SYS calls. Might be worth checking, though, or even just using the library directly.

Share this post


Link to post
Share on other sites
kop0113    2453
The closest you can get to a "pure" OpenGL rendering context on X11 is by just using the X11 library itself.
Some of the older OpenGL books go into this but unfortunately it is becoming a bit of a lost art in the newer literature.

A good example is http://content.gpwiki.org/index.php/OpenGL:Tutorials:Setting_up_OpenGL_on_X11
As you can see, this uses GLX (which is what provides the rendering context).

Some more typical rendering contexts include...

glut
wxGLWidget (wxWidgets)
QtOpenGL (Qt)
Gtkglext (Gtk)
SDL

Personally, even though I am a C++ developer, I still highly recommend Glut. It is really portable and is already installed on most Linux distros. The 100% free implementation is called FreeGlut. Edited by Karsten_

Share this post


Link to post
Share on other sites
ic0de    1012
I use SDL and OpenGL for my game. I found porting my game from windows to Linux was a breeze I didn't even need to edit any code and the computer seemed to have all the files I needed. As far as I know there is no such thing as "pure" OpenGL you will always need some way to window it. I also find using Glew helps but to each his own.

Share this post


Link to post
Share on other sites
larspensjo    1561
If you want something portable that gives you only the OpenGL context, and nothing more, then I recommend [url="http://www.glfw.org/"]glfw[/url]. Well, it gives you a little more, like interface to I/O (e.g. mouse, keyboard). In my opinion, glfw is a stronger and cleaner library than glut.

Share this post


Link to post
Share on other sites
alh420    5995
[quote name='Neosettler' timestamp='1353619415' post='5003320']
Thank you Bregma,

Your answer almost gave me a heart attack. For all the porting a need to do, I thought OpenGL would be a breeze.
[/quote]

Note though that all these libraries are only for setting up the GL context and getting a window to draw in, and some input (and possibly a few utility functions)

Those of course have to be OS specific.

All the actual rendering is the same standard OpenGL, as long as you use the same profile, so no need for heart attacks :)

(some drivers might have bugs, or allow some invalid behaviour that breaks on other drivers, but that is a separate story... ) Edited by Olof Hedman

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By Zaphyk
      I am developing my engine using the OpenGL 3.3 compatibility profile. It runs as expected on my NVIDIA card and on my Intel Card however when I tried it on an AMD setup it ran 3 times worse than on the other setups. Could this be a AMD driver thing or is this probably a problem with my OGL code? Could a different code standard create such bad performance?
    • By Kjell Andersson
      I'm trying to get some legacy OpenGL code to run with a shader pipeline,
      The legacy code uses glVertexPointer(), glColorPointer(), glNormalPointer() and glTexCoordPointer() to supply the vertex information.
      I know that it should be using setVertexAttribPointer() etc to clearly define the layout but that is not an option right now since the legacy code can't be modified to that extent.
      I've got a version 330 vertex shader to somewhat work:
      #version 330 uniform mat4 osg_ModelViewProjectionMatrix; uniform mat4 osg_ModelViewMatrix; layout(location = 0) in vec4 Vertex; layout(location = 2) in vec4 Normal; // Velocity layout(location = 3) in vec3 TexCoord; // TODO: is this the right layout location? out VertexData { vec4 color; vec3 velocity; float size; } VertexOut; void main(void) { vec4 p0 = Vertex; vec4 p1 = Vertex + vec4(Normal.x, Normal.y, Normal.z, 0.0f); vec3 velocity = (osg_ModelViewProjectionMatrix * p1 - osg_ModelViewProjectionMatrix * p0).xyz; VertexOut.velocity = velocity; VertexOut.size = TexCoord.y; gl_Position = osg_ModelViewMatrix * Vertex; } What works is the Vertex and Normal information that the legacy C++ OpenGL code seem to provide in layout location 0 and 2. This is fine.
      What I'm not getting to work is the TexCoord information that is supplied by a glTexCoordPointer() call in C++.
      Question:
      What layout location is the old standard pipeline using for glTexCoordPointer()? Or is this undefined?
       
      Side note: I'm trying to get an OpenSceneGraph 3.4.0 particle system to use custom vertex, geometry and fragment shaders for rendering the particles.
    • By markshaw001
      Hi i am new to this forum  i wanted to ask for help from all of you i want to generate real time terrain using a 32 bit heightmap i am good at c++ and have started learning Opengl as i am very interested in making landscapes in opengl i have looked around the internet for help about this topic but i am not getting the hang of the concepts and what they are doing can some here suggests me some good resources for making terrain engine please for example like tutorials,books etc so that i can understand the whole concept of terrain generation.
       
    • By KarimIO
      Hey guys. I'm trying to get my application to work on my Nvidia GTX 970 desktop. It currently works on my Intel HD 3000 laptop, but on the desktop, every bind textures specifically from framebuffers, I get half a second of lag. This is done 4 times as I have three RGBA textures and one depth 32F buffer. I tried to use debugging software for the first time - RenderDoc only shows SwapBuffers() and no OGL calls, while Nvidia Nsight crashes upon execution, so neither are helpful. Without binding it runs regularly. This does not happen with non-framebuffer binds.
      GLFramebuffer::GLFramebuffer(FramebufferCreateInfo createInfo) { glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); textures = new GLuint[createInfo.numColorTargets]; glGenTextures(createInfo.numColorTargets, textures); GLenum *DrawBuffers = new GLenum[createInfo.numColorTargets]; for (uint32_t i = 0; i < createInfo.numColorTargets; i++) { glBindTexture(GL_TEXTURE_2D, textures[i]); GLint internalFormat; GLenum format; TranslateFormats(createInfo.colorFormats[i], format, internalFormat); // returns GL_RGBA and GL_RGBA glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, createInfo.width, createInfo.height, 0, format, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); DrawBuffers[i] = GL_COLOR_ATTACHMENT0 + i; glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, textures[i], 0); } if (createInfo.depthFormat != FORMAT_DEPTH_NONE) { GLenum depthFormat; switch (createInfo.depthFormat) { case FORMAT_DEPTH_16: depthFormat = GL_DEPTH_COMPONENT16; break; case FORMAT_DEPTH_24: depthFormat = GL_DEPTH_COMPONENT24; break; case FORMAT_DEPTH_32: depthFormat = GL_DEPTH_COMPONENT32; break; case FORMAT_DEPTH_24_STENCIL_8: depthFormat = GL_DEPTH24_STENCIL8; break; case FORMAT_DEPTH_32_STENCIL_8: depthFormat = GL_DEPTH32F_STENCIL8; break; } glGenTextures(1, &depthrenderbuffer); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); glTexImage2D(GL_TEXTURE_2D, 0, depthFormat, createInfo.width, createInfo.height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthrenderbuffer, 0); } if (createInfo.numColorTargets > 0) glDrawBuffers(createInfo.numColorTargets, DrawBuffers); else glDrawBuffer(GL_NONE); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) std::cout << "Framebuffer Incomplete\n"; glBindFramebuffer(GL_FRAMEBUFFER, 0); width = createInfo.width; height = createInfo.height; } // ... // FBO Creation FramebufferCreateInfo gbufferCI; gbufferCI.colorFormats = gbufferCFs.data(); gbufferCI.depthFormat = FORMAT_DEPTH_32; gbufferCI.numColorTargets = gbufferCFs.size(); gbufferCI.width = engine.settings.resolutionX; gbufferCI.height = engine.settings.resolutionY; gbufferCI.renderPass = nullptr; gbuffer = graphicsWrapper->CreateFramebuffer(gbufferCI); // Bind glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); // Draw here... // Bind to textures glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, textures[0]); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, textures[1]); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, textures[2]); glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); Here is an extract of my code. I can't think of anything else to include. I've really been butting my head into a wall trying to think of a reason but I can think of none and all my research yields nothing. Thanks in advance!
    • By Adrianensis
      Hi everyone, I've shared my 2D Game Engine source code. It's the result of 4 years working on it (and I still continue improving features ) and I want to share with the community. You can see some videos on youtube and some demo gifs on my twitter account.
      This Engine has been developed as End-of-Degree Project and it is coded in Javascript, WebGL and GLSL. The engine is written from scratch.
      This is not a professional engine but it's for learning purposes, so anyone can review the code an learn basis about graphics, physics or game engine architecture. Source code on this GitHub repository.
      I'm available for a good conversation about Game Engine / Graphics Programming
  • Popular Now