Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Problem with uniform in GLSL shader  (Read 3054 times)

0 Members and 1 Guest are viewing this topic.

Peteck

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Problem with uniform in GLSL shader
« on: August 05, 2014, 09:55:32 pm »
So right now I'm playing around with some OpenGL stuff. Well I'm trying to make a deferred rendering application to better learn what deferred rendering is and how it works. But I have a wierd problem. I think it may be some kind of problem with the size of different floats. Hmm but well here we go with some code.

First of all I create my textures and add them to a framebuffer.
(click to show/hide)

And my fragment shader look like this.
(click to show/hide)

But I have problem when I'm setting "texCoords" right after main in my fragment shader. When using an uniform to pass the values. If I use the uniform I get the first and bad looking image attachment. If I just hard code the value instead of using the uniform, I get the second and good looking image attachment.

And function for setting the uniform look like so.
(click to show/hide)

So are there any out there on this forum that may have an idea why this happens?

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Problem with uniform in GLSL shader
« Reply #1 on: August 05, 2014, 11:19:28 pm »
The first habit you should develop when writing GL code is to check for GL errors. If you don't, you will waste a lot of time looking for the error in the wrong places. Take a look into SFML's source and you will see that every GL call is surrounded by SFML's glCheck() macro that automatically checks the enclosed GL call. This will tell you exactly what line produced what error so that you can easily fix them when they happen.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Peteck

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: Problem with uniform in GLSL shader
« Reply #2 on: August 06, 2014, 12:02:14 am »
The first habit you should develop when writing GL code is to check for GL errors. If you don't, you will waste a lot of time looking for the error in the wrong places. Take a look into SFML's source and you will see that every GL call is surrounded by SFML's glCheck() macro that automatically checks the enclosed GL call. This will tell you exactly what line produced what error so that you can easily fix them when they happen.
Well, I took your advice and used glGetError() to see if there was any errors. And and got only one. So I tracked it down, fixed it, and then all was fine. I was screwing up some uniform locations on the samplers, which I didn't need to do anyways.

Actually I was like "well, I check for errors on shaders, frame buffers..." and so on and was ready to say I wasn't doing anything wrong in my c++ code. But I was wrong, so thank you for the advice to check for OpenGL errors. Didn't even knew anything about the glGetError() function. This may will help me alot in the future developing OpenGL.

lolz123

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
Re: Problem with uniform in GLSL shader
« Reply #3 on: August 07, 2014, 05:03:16 pm »
Try using CodeXL. It tells you all GL/CL/C++ errors, and you can pause the execution at any time and see what is going on in the framebuffers, and what the uniforms are actually set to.

Some errors may "disappear" when you use glGetError, depending on when you call the function. But CodeXL will break immediately on it if you set it to break on all GL errors.

My guess is that you are not binding the shader before setting the uniform. That or the uniform location is wrong. I think you can use layout qualifiers to guarantee that the uniforms are at a certain index.
Have you heard about the new Cray super computer?  It’s so fast, it executes an infinite loop in 6 seconds.