opengl,state-machines,render-to-texture , Opengl - Is glDrawBuffers modification stored in a FBO? No?


Opengl - Is glDrawBuffers modification stored in a FBO? No?

Question:

Tag: opengl,state-machines,render-to-texture

I try to create a FrameBuffer with 2 textures attaching to it (Multi Render Targets). Then in every time step, both textures are cleared and painted, as following code. (Some part will be replaced as pseudo code to make it shorter.)

Version 1

//beginning of the 1st time step
initialize(framebufferID12)
//^ I quite sure it is done correctly, 
//^ Note : there is no glDrawBuffers()  calling

loop , do once every time step {
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebufferID12);  
    //(#1#) a line will be add here in version 2 (see belowed) <------------
    glClearColor (0.5f, 0.0f, 0.5f, 0.0f);
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    //  paint a lot of object here , using glsl (Shader .frag, .vert)
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);  
}

All objects are painted correctly to both texture, but only the first texture (ATTACHMENT0) is cleared every frame, which is wrong.

Version 2

I try to insert a line of code ...

glDrawBuffers({ATTACHMENT0,ATTACHMENT1}) ;  

at (#1#) and it works as expected i.e. clear all two textures.

(image http://s13.postimg.org/66k9lr5av/gl_Draw_Buffer.jpg)

Version 3

From version 2, I move that glDrawBuffers() statement to be inside frame buffer initialization like this

initialize(int framebufferID12){
    int nameFBO = glGenFramebuffersEXT();
    int nameTexture0=glGenTextures();
    int nameTexture1=glGenTextures();
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,nameFBO);
      glBindTexture(nameTexture0);
      glTexImage2D( .... ); glTexParameteri(...);
      glFramebufferTexture2DEXT( ATTACHMENT0, nameTexture0);
      glBindTexture(nameTexture1);
      glTexImage2D( .... ); glTexParameteri(...);
      glFramebufferTexture2DEXT( ATTACHMENT0, nameTexture1);
      glDrawBuffers({ATTACHMENT0,ATTACHMENT1}) ;  //<--- moved here ---
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0);
    return nameFBO ;
}

It is no longer work (symptom like version 1), why?

The opengl manual said that "changes to context state will be stored in this object", so the state modification from glDrawBuffers() will be stored in "framebufferID12" right? Then, why I have to call it every time step (or every time I change FBO)

I may misunderstand some opengl's concept, someone enlighten me please.

Edit 1: Thank j-p. I agree that it is make sense, but shouldn't the state be recorded in the FBO already?

Edit 2 (accept answer): Reto Koradi's answer is correct! I am using a not-so-standard library called LWJGL.


Answer:

Yes, the draw buffers setting is part of the framebuffer state. If you look at for example the OpenGL 3.3 spec document, it is listed in table 6.23 on page 299, titled "Framebuffer (state per framebuffer object)".

The default value for FBOs is a single draw buffer, which is GL_COLOR_ATTACHMENT0. From the same spec, page 214:

For framebuffer objects, in the initial state the draw buffer for fragment color zero is COLOR_ATTACHMENT0. For both the default framebuffer and framebuffer objects, the initial state of draw buffers for fragment colors other then zero is NONE.

So it's expected that if you have more than one draw buffer, you need the explicit glDrawBuffers() call.

Now, why it doesn't seem to work for you if you make the glDrawBuffers() call as part of the FBO setup, that's somewhat mysterious. One thing I notice in your code is that you're using the EXT form of the FBO calls. I suspect that this might have something to do with your problem.

FBOs have been part of standard OpenGL since version 3.0. If there's any way for you to use OpenGL 3.0 or later, I would strongly recommend that you use the standard entry points. While the extensions normally still work even after the functionality has become standard, I would always be skeptical how they interact with other features. Particularly, there were multiple extensions for FBO functionality before 3.0, with different behavior. I wouldn't be surprised if some of them interact differently with other OpenGL calls compared to the standard FBO functionality.

So, try using the standard entry points (the ones without the EXT in their name). That will hopefully solve your problem.


Related:


Ambient and Specular lighting not working correctly in GLSL


opengl,glsl,lighting,phong
In my lighting scene, for some reason the ambient lighting isn't working at all. The whole model is the same brightness, no matter which way it is facing. I tried getting rid of the attenuation but it still has the same results. Along with that, the specular lighting is always...

glDeleteRenderbuffersEXT via remote desktop


windows,opengl,remote-desktop
I have an application that uses OpenGL. If I connect to a computer via Windows Remote Desktop I get an exception "Extension function glDeleteRenderbuffersEXT not supported" from my application. I think the exception is caused because Remote Desktop does not support the extension. My plan is to detect if the...

OpenGL stops rendering, possibly after an update


c++,opengl,glfw
I am working on a small OpenGL project using the GLFW library. Everything was fine until from one day, I can't get it to render anything except the background. So I loaded up an older version, which I am sure worked just fine and the same thing happens. I then...

OpenGL Texture rendering as black


objective-c,opengl,quartz-2d,syphon
I'm using the Syphon framework to try and push frames of video from a server to a client application. Syphon requires you to use OpenGL textures instead of normal images. Because of this, I'm trying to render a CGImageRef as a texture and send it on to be published. I'm...

OpenGL program works only in Debug mode in Visual Studio 2013


c++,opengl,visual-studio-2013,release
my small OpenGL application works fine in Debug mode, but if I build it in Release mode I often get this error: Shader Creation Error: - Vertex shader failed to compile with the following errors: ERROR: 0:22: error(#132) Syntax error: "]" parse error ERROR: error(#273) 1 compilation errors. No code...

Effect of rendering calls on performance


c++,opengl
Consider a situation , Case 1 : I am giving opengl calls to draw the world by drawing all polygons. So all polygons will be drawn according to all objects exist. (Considered all translation rotation). Case 2 : I will allow only polygons that are in field of view(FOV) of...

OpengGL face culing for selected faces


opengl
I'm importing geometry data from a file and the objects could be split in two categories: open or closed. If all of them were closed, I could just cull the backfaces, but since some of them are not closed, I cannot, because the user could see only the front faces....

R32I sampler2D returns always 0


c++,opengl
I have a (default vertex and) fragment shader that should resize textures and scale their color by a specific factor for brightness correction. The result is rendered into an GL_UNSIGNED_INT_8_8_8_8 framebuffer. #version 330 uniform sampler2D tex; uniform vec2 screenSize; uniform float scale; layout(location = 0) out vec4 color; void main()...

Switching from perspective orthographic projection in OpenGL


c#,opengl,opentk
I'm really new to OpenGL and trying to learn from the 'modern' OpenGL tutorials. I'm using C# and OpenTK. I'm setting my projectionMatrix with this code: _projectionMatrix = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver3, GetAspectRatio(), 0.1f, 100f); After I set it, I upload it to the shaders, use for transformations, etc. Everything is working well...

Need Minimum Textures required for OpenGL


opengl
Quick question, what is the minimum amount of textures that can be bound for the fragment shader that a OpenGL implementation is required to have? Note: I would like to know this for OpenGL 1.5, for OpenGL 2.0, and OpenGL 2.1...

Multitexturing theory with texture objects and samplers


opengl,textures
I couldn't find any good theory articles on how to code multitexturing with either only texture objects or texture objects plus samplers. I just don't know how to manage the glActiveTexture function and what it exactly does. glGenTextures(1, &texture); glActiveTexture(GL_TEXTURE0 + 0); // Number between 0 and GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS glBindTexture(GL_TEXTURE_2D, texture);...

Can the OpenGL 'deprecated' functions possibly be unsupported?


c++,c,opengl,graphics,deprecated
I am testing with glDrawPixels to port my simple pixel-drawn 2D game from Windows API to OpenGL with GLFW. It runs nicely with FPS over 100, additionally cross-platform. Just one thing that is slightly annoying me is that I'm using a deprecated feature. I don't see any problems now, but...

Win32 Message Pump and std::thread Used to Create OpenGL Context and Render


multithreading,winapi,opengl,c++11
If I have a function that does the following: bool foo::init() { [Code that creates window] std::thread run(std::bind(&foo::run, this)); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } } Where run is defined as: void foo::run() { [Code that creates initial opengl context] [Code that recreates window based on new...

The order of the linked libraries C++ linker


c++,opengl,opencl
I was debugging a project that depends on a set of libraries including libfreenect, OpenGL and OpenCL. The problem is that a black screen was the output. As a debugging option, I have removed the OpenCL code and the linked library completely trying to make sure that OpenGL works fine...

OpenGL: Defining variables in shaders


opengl,glsl
My OpenGL program, using GLSL for shaders, has a simple vertex and fragment shader (given by a tutorial). The vertex shader is: #version 330 layout (location = 0) in vec3 Position; void main() { gl_Position = vec4(0.5 * Position.x, 0.5 * Position.y, Position.z, 1.0); } And the fragment shader is:...

Unable to render a texture on a quad


c++,opengl,textures,texturing
I am trying to program a simple game in C++ using OpenGL for graphics. In my game, I have objects that are rendered onscreen as a white square. I would like to be able to bind an image as a texture to these objects, so that I can render an...

OpenGL: GL_FRAMEBUFFER_UNSUPPORTED on specific combinations of framebuffer attachments


c++,opengl,textures,nvidia,framebuffer
Im trying to attach multiple targets to a framebuffer object. I have the following problem: There is no error, when using float texture attachments and a depth attachment. There is also no error, when using float texture attachments and integer texture attachments. Although these combinations work, I cant use float,...

OpenGL: Using glColorPointer make color weird


opengl
Like the picture showed in the link below. I want to color my robot hand with white color(RGB: 0.9 0.9 0.9). When I use glColor3f, the white color display correctly. But when I store RGB data in GLfloat array and call glColorPointer, the color becomes so weird. Here is code...

OpenGL glTexImage2D memory issue


c,opengl
I'm loading a cubemap to create a skybox, everything is fine and the skybox renders properly with a correct texture application. However, I decided to check my program safety with valgrind, Valgrind gives this error: http://pastebin.com/seqmXjyx The line 53 in sky.c is: glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, texture.width, texture.height, 0,...

Opengl - Is glDrawBuffers modification stored in a FBO? No?


opengl,state-machines,render-to-texture
I try to create a FrameBuffer with 2 textures attaching to it (Multi Render Targets). Then in every time step, both textures are cleared and painted, as following code. (Some part will be replaced as pseudo code to make it shorter.) Version 1 //beginning of the 1st time step initialize(framebufferID12)...

GLSL - program link error: Slot 0 unavailable from layout location request


c++,opengl,glsl
I'm trying to draw a textured quad copying some code from a tutorial but I'm afraid there is a problem with the shaders. Both the vertex shader and the fragment shader compilation works, but when linking the program I get the error: ERROR: Active attribute aliasing. Slot 0 unavailable for...

wxWidgets with AUI: OpenGL render loop method and wxPaintEvent


c++,user-interface,opengl,wxwidgets
The method I traditionally use of drawing to an OpenGL canvas with wxWidgets is to trigger a 30 hertz timed refresh() from the current OpenGL canvas, which then generates a "wxEVT_PAINT", which I can propogate out to the rest of the frame. I also bind to the wxEVT_PAINT and call...

What is the difference between glUseProgram() and glUseShaderProgram()?


c++,c,opengl,shader
In OpenGL what is the difference between glUseProgram() and glUseShaderProgram()? It seems in MESA and Nvidia provided glext.h, and in GLEW, both are defined, and both seem to do basically the same thing. I find documentation for glUseProgram() but not for glUseShaderProgram(). Are they truly interchangeable?...

OpenGL, Access violation


c++,opengl,access-violation
I am making an OpenGL project in Visual Studio 2010. I am following a tutorial from youtube. I don't know where the error is, and I have this error: Unhandled exception at 0x00000000 in OpenGL First Game.exe: 0xC0000005: Access violation. Main.cpp #include <GL/glew.h> #include <iostream> #include <GL/glut.h> #include "Sprite.h" Sprite...

Why normal mapping doesn't appear correctly?


opengl,jogl
I'm applying bump mapping to a tree. When no normal mapping applied, it appears like this. But when a normal texture is used, it turned out to be too aggressive as follow which is ugly. I checked tangent data which should be fine. So I was wondering if it's because...

Spotlight with shadows becomes square-like


c++,opengl,graphics,shader,shadow
I've been following a two part tutorial on shadow mapping from OGLDev (part 1, part 2) for a couple of days now, and I've nearly finished implementing it. My problem is that when I enable shadow maps the illuminated region which shadows appear in appears as a "strip" and I'm...

What OpenGL loading library to use? [closed]


c++,opengl
Does anybody know an OpenGL loading library similar go GLEW that loads functions for OpenGL 2.0 but DOES NOT define them as macros?

Creating GUI with OpenGL


java,opengl
I am trying to write a Java programm using LWJGL 3 and so far I've made it to creating a window, rendering to it and getting basic input. But I've ran into a problem with creating GUI and namely text fields that my programm requires. I found information that there...

OpenGL: try to draw lines using VBO(vertex buffer object), it doesn't display


c,opengl,vbo,vertex-buffer-objects
I try to switch my openGL code from using display list to using VBO. In the code, I tried to draw a green-grid floor, which is composed by green lines in parallel with x-axis and green lines in parallel with z-axis. But when the program runs, floor doesn't display. And...

GLFW3 create window returns null


c,opengl,struct,code-separation
I was trying to put all GLFW3 init code from main to separate file. When I'm running the code, I get EXC_BAD_ACCESS on glew init function, because GLFW could not create window. Before code separation everything was ok. Is it possible to have GLFW setup code in other function? I'm...

Passing an int to a function, then using that int to create an array


c++,arrays,opengl
I'm trying to create a textureLoader class for my openGL project and I can't initialize an array of textures inside of my class constructor because the the array won't accept anything unless it's a const int. To paint you a simple picture... myFunction(NUM) { GLuint textures[NUM]; } My past Failures...

OpenGL4: Rotation looks all wrong


c++,opengl,glm-math
Here's the vertex buffer information of the quad I'm drawing: static const GLfloat pv_quad[] = { -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 0.0f, -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, }; This quad is used to draw 2D frames on the screen as part of the graphical user interface. The class I...

Changing texture parameters at runtime


c++,opengl
I am an OpenGL beginner and I have built a small engine for a universitary course. Now one constraint/feature I need to implement is to change the texture quality (interpolation) at runtime. So instead of e.g.: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); it should be changed to mipmaps glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR) Now I...

How to update the “forward” movement in OpenGL


c++,opengl,camera,fps
I have a problem with my OpenGL application that you can clearly see in this gif. Basically I would like to move in the direction pointed by the cursor, but this doesn't happen and instead the "forward" direction remains the same. For example if I turn 180° and press "w"...

Is it possible to build a heatmap from point data at 60 times per second?


c++,opengl,visualization,simulation,heatmap
I'm working on a simulation for clouds (actual clouds) where the clouds are simulated by 3D points, then projected into a 2D heatmap, about 640x480 units big. The number of points is about 50k, which is as small as I can go without the simulation breaking, but I can't seem...

Why are shaders and programs stored as integers in OpenGL?


c++,opengl,opengl-es,integer,shader
I'm following the "OpenGL Superbible" book and I can't help but notice that when we create a shader and create the program that we attach the shaders to, we store them as GLuint which are unsigned integers. Why are they stored as numbers? What does the value of the number...

glclearcolor best color?


opengl,optimization
this might seam like a stupid question but i was wondering, when calling glClear(GL11.GL_COLOR_BUFFER_BIT); glClearColor(1, 0, 0, 1); to clear the screen in my opengl project is there any performance differences for using different colors? i mean if for example i clear to red vs blue/green/*insert any color will it...

OpenGL: Strange bahaviour of VBO deletion?


c++,opengl,vbo,opengl-3,vao
I am getting a strange issue in Vertex Buffer Object (VBO). I created a class that includes VBO creation and deletion. I delete all the VBOs (with glDeleteBuffers()) in the destructor of the class. Now I created 2 OpenGL context windows each running with VBO class. Now when I close...

Reading a shader from a .txt file using a structure


c++,opengl,struct,shader
I've started learning how to use OpenGL and I absolutely hate having my shaders declared as global variables before my main(). I thought it would be cool to make a structure or class that would read the shader from a file in my project directory. The file reading works perfectly...

Java: FloatBuffer to OpenGL - wrap() vs. allocate() vs. BufferUtils.createBuffer()


java,opengl,buffer
Datasource: float[] v = { ... }; Working example: FloatBuffer buf = BufferUtils.createFloatBuffer(v.length); buf.put(v); buf.flip(); // or buf.rewind() The buffer can now be uploaded to opengl and works fine: ... glBufferData(..., buf, ...); ... Why do the following examples of the buffer creation not also work? Not working 1: FloatBuffer...

How to create latitudinal (horizontal) contour lines in GLSL?


opengl,glsl,webgl
I'm aiming for this effect: (horizontal-only contour lines): I did find this example, however it creates horizontal and vertical contour lines. I can't quite wrap my head around how the call to fwidth() is generating the lines. uniform float gsize;//size of the grid uniform float gwidth;//grid lines'width in pixels varying...

How can I render an infinite 2D grid in GLSL?


opengl,glsl
Ideally, what I'd like to do is draw a single quad and have GLSL handle the creation of the actual gridlines. In my attempt so far the vertex shader: #version 400 layout (location = 0) in vec4 in_position; layout (location = 2) in vec3 in_UV; uniform mat4 model; uniform mat4...

Need help finding out why the texture doesn't load


java,opengl
Trying to find a way to render a simple 2D image in Java using OpenGL I stumbled upon a more or less understandable class that does all of the image loading for you which I could not understand how to do. I believe it belongs to a person named Krythic...

C++ Opengl - How to load tgas and pngs in modern OpenGL? [on hold]


image,opengl,c++11,png,tga
I am looking for a way to load tgas and pngs in C++ Opengl - I dislike the idea of using a library though. Is there any sample code / links / advice you could give me in this topic?...

scale texture opengl 2


opengl,textures,scale
I have a rectangle in opengl 2 and I'm using a texture for it. It Works, but the texture is repeated over the rectangle, and what I want is to adapt to the size of the rectangle. I have read in this tutorial about the different parameters you can set...

OpenGL - translation stretches and distorts sprite


c++,opengl,transform,translation,distortion
I am loosely following the very handy tutorial at opengl-tutorial.org. I've been able to create a mesh, draw a sprite to it, and rotate and scale that mesh perfectly fine. However, I'm running into some issues when trying to translate the mesh. (pictures below) Here's an update function on the...

Qt OpenGL transform feedback buffer functions missing


c++,qt,opengl,transform-feedback
I've been following a tutorial series for learning OpenGL, and the current tutorial I'm trying to do involves creating particle systems using the OpenGL transform feedback buffer. In my application I've been using Qt version 5.4.2 for simple 2D interface design, as well as for 3D rendering since it seems...

Haskell - Could not deduce … from Context error - OpenGL AsUniform class type


class,haskell,opengl,types,uniform
I'm working on making my data types general instead of taking in the OpenGL type GLfloat. So I started making it take in type a and then just replacing everything with that. Now, I've come to a point where I'm setting uniform variables, but they take in GLfloat's. I'm using...

No OpenGL context is current in the current thread


java,opengl,lwjgl
I'm following a tutorial on youtube but I have a problem with OpenGL that I'm not able to solve. I have no idea how I can fix it. Exception in thread "EndlessRunner" java.lang.IllegalStateException: No OpenGL context is current in the current thread. at org.lwjgl.opengl.GLContextWindows.createFromCurrent(GLContextWindows.java:61) at org.lwjgl.opengl.GLContext.createFromCurrent(GLContext.java:36) at net.alfredo.Main.init(Main.java:59) at net.alfredo.Main.run(Main.java:91)...