Jump to content

  • Log In with Google      Sign In   
  • Create Account

Johan Gustafsson

Member Since 19 Dec 2003
Offline Last Active Dec 19 2014 09:32 AM

Topics I've Started

FBO depth wont clear

04 November 2013 - 04:53 PM

This has been solved now: I had to call glDepthMask(GL_TRUE) before clearing.

Hello,
I am having trouble with the depth buffer and my fbo. Everything renders correctly if I disable depth test or if I render directly to the frame buffer instead of the fbo. It looks like the depth buffer that is attached to the fbo is not cleared correctly, I can also see some flickering of the rendered object when I move the camera. My box is rendered correctly in the first frame when I do frame by frame stepping in CodeXL but it is not visible in the following frames.

I get no errors from CheckFrameBufferStatus or GetError and the fbo looks ok when I check it in CodeXL (1 texture and 1 render buffer, fromat = GL_DEPTH_COMPONENT24, type = GL_FLOAT).

Creation of the fbo:
GL.GenFramebuffers(1, out Handles[index].FrameBufferObject);
GL.BindFramebuffer(FramebufferTarget.Framebuffer, Handles[index].FrameBufferObject);

Handles[index].DrawBuffers = new DrawBuffersEnum[textureHandles.Length];

for (var i = 0; i < textureHandles.Length; i++)
{
    Handles[index].DrawBuffers[i] = DrawBuffersEnum.ColorAttachment0 + i;
    GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0 + i, OGL.TextureTarget.Texture2D, textureHandles[i], 0);
}

GL.GenRenderbuffers(1, out Handles[index].DepthBufferObject);
GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, Handles[index].DepthBufferObject);
GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, RenderbufferStorage.DepthComponent24, width, height);

GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, RenderbufferTarget.Renderbuffer, Handles[index].DepthBufferObject);
GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, 0);

var status = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer);
if (status != FramebufferErrorCode.FramebufferComplete)
{
    // Log error and clean up if neccecary
}

GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
Below are all the draw calls for a complete frame, extracted while debugging with CodeXL.
// Render the crate to the texture
glBindFramebuffer(GL_FRAMEBUFFER, 1)
glDrawBuffers(1, {GL_COLOR_ATTACHMENT0})
glViewport(0, 0, 512, 512)
glClearColor(0, 0, 0, 1)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)
glUseProgram(33) [Context 3 - program 33: shader 31, shader 32]
glDisable(GL_BLEND)
glEnable(GL_DEPTH_TEST)
glDepthMask(TRUE)
glEnable(GL_CULL_FACE)
glBlendFunc(0, 1)
glCullFace(GL_BACK)
glDepthFunc(GL_LESS)
glUniformMatrix4fv(0, 1, FALSE, {0.47494337, -1.4067751, 0.32057661, 0.32045144} {5.5997848e-008, 0.6356858, 0.93057901, 0.9302156} {0.85067475, 0.78542173, -0.17898236, -0.17891248} {1.7013494, 0.80802053, -1.6746986, -1.4740837})
glBindVertexArray(4)
glDrawElements(GL_TRIANGLES, 612, GL_UNSIGNED_INT, 0x000000)

// Render texture to fullscreen quad
glBindFramebuffer(GL_FRAMEBUFFER, 0)
glDrawBuffer(GL_BACK)
glViewport(0, 0, 1280, 720)
glClearColor(0, 0, 0, 1)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)
glUseProgram(6) [Context 3 - program 6: shader 4, shader 5]
glActiveTexture(GL_TEXTURE0)
glBindTexture(GL_TEXTURE_2D, 2) [Context 3 - Texture 2: Context 3 - Texture 2]
glDisable(GL_BLEND)
glDisable(GL_DEPTH_TEST)
glDepthMask(FALSE)
glEnable(GL_CULL_FACE)
glBlendFunc(0, 1)
glCullFace(GL_BACK)
glDepthFunc(GL_LESS)
glUniform1i(0, 0)
glBindVertexArray(5)
glDrawElements(GL_TRIANGLES, 18, GL_UNSIGNED_INT, 0x000000)
wglGetCurrentDC()
wglSwapBuffers(0xE40123A5)
Anyone got any ideas? I have searched on google but have not found anything that helps so far. It feels like I'm missing something obvious in my opengl calls.
 
Update: Actual fbo setup as reported by CodeXL, everything looks ok to me.
// Texture setup
glGenTextures(1, {0})
glBindTexture(GL_TEXTURE_2D, 2) [Context 4 - Texture 2: No preview available]
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 512, 512, 0, GL_RGBA, GL_FLOAT, 0x000000) [Context 4 - Texture 2: No preview available]
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) [Context 4 - Texture 2: Context 4 - Texture 2]
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) [Context 4 - Texture 2: Context 4 - Texture 2]
glFinish()
glGetError()

// Frame buffer setup
glGenFramebuffers(1, 0x29A83C4)
glBindFramebuffer(GL_FRAMEBUFFER, 1)

// Attach texture
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 2, 0)

// Create and attach depth render buffer
glGenRenderbuffers(1, 0x29A83C8)
glBindRenderbuffer(GL_RENDERBUFFER, 1)
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, 512, 512)

glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 1)
glBindRenderbuffer(GL_RENDERBUFFER, 0)

glCheckFramebufferStatus(GL_FRAMEBUFFER)
glBindFramebuffer(GL_FRAMEBUFFER, 0)

RymdspeletHD has been released!

21 January 2011 - 03:16 PM

Hi,
I have just released the final version of my latest game RymdspeletHD, (that's Swedish for "The Space Game HD").
It's your standard asteroids-like space shooter with a few nice features such as an online highscore and an upgrade system that let's you upgrade your ship between levels.

The game is written in C++ with HGE. I have been working on it for about 12 months but the total amount of time spent is probably closer to 60 hours, not including the previous incarnations of the game.

It is made for Windows but it may work on Linux through wine.

It can be downloaded here.

http://www.rymdspelet.net/

I have embedded a video showcasing some gameplay, or you can watch it in hd here.

http://www.youtube.com/watch?v=J5rHl8OFw2I

RymdspeletHD Beta

12 May 2010 - 08:20 AM

RymdspeletHD is an addictive space shooter with ship upgrading, an online high score and awesome explosions. It is written in C++ using the HGE engine. The current beta version can be downloaded at http://www.rymdspelet.net A video can be found here

[SlimDX] Setting vertex shader constants

08 September 2009 - 04:27 AM

Hi, I'm trying to set vertex shader constants in SlimDX, but doing so gives me "D3DERR_INVALIDCALL: Invalid call (-2005530516)". Here is my code:
Renderer.Device.VertexShader = shader.VertexShader;
Renderer.Device.PixelShader = shader.PixelShader;

shader.VertexShader.Function.ConstantTable.SetValue(Renderer.Device, new SlimDX.Direct3D9.EffectHandle("worldViewProj"), worldViewProjection);

Is there something else that I have to do?

Rymdspelet V version 1.4

02 March 2009 - 02:47 AM

The brand new version 1.4 of Rymdspelet V is now available - featuring bigger asteroids, cooler backgrounds and an awesome highscore list. Direct download Online highscore Read me and change log

PARTNERS