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

Login with username, password and session length

 
Advanced search

1075919 Posts in 44152 Topics- by 36120 Members - Latest Member: Royalhandstudios

December 29, 2014, 03:15:33 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Binding uniform value
Pages: [1]
Print
Author Topic: Binding uniform value  (Read 405 times)
kamac
Level 10
*****


Notorious posts editor


View Profile Email
« on: July 03, 2012, 07:22:42 AM »

Gosh, gosh, gosh.

30 minutes spent, trying to find out what's causing that issue.
Namely, I want to bind a uniform value to my program id. Here's how I do it:

Code:
const char *name = "mytexture";
GLint uniform_myTexture = glGetUniformLocation(program_id,name);
if(uniform_myTexture == -1)
{
printf("ERROR: Could not bind uniform %s to program %s\n",name,program_name);
return;
}

Here are my shaders that I compile:

(vertex shader)

Code:
#version 120

attribute vec3 coord3d;
uniform mat4 MVP;
attribute vec2 UV;
varying vec2 UV_coord;

void main()
{
gl_Position = MVP * vec4(coord3d,1);
UV_coord = UV;
}

(fragment shader)

Code:
#version 120

uniform sampler2D mytexture;
uniform vec4 color;

varying vec2 UV_coord;

void main()
{
gl_FragColor = texture2D(mytexture,UV_coord) * color;
gl_FragColor = vec4(1.0,1.0,1.0,1.0);
}

Everything bind succefully but not

uniform sampler2D mytexture;
uniform vec4 color;

which are inside my fragment shader... Those that are inside vertex shader bind correctly.
I remember that I've had this issue earlier, but I don't remember the solution  Angry

Do you guys know it?
Logged

Nothing to do here
owendeery
Level 2
**



View Profile WWW Email
« Reply #1 on: July 03, 2012, 07:35:53 AM »

Is the uniform location that you get invalid? Or does it just not bind to that location properly?

I assume that you're checking shader compilation errors as well, since both binding problems are occurring in the same shader file.
Logged

kamac
Level 10
*****


Notorious posts editor


View Profile Email
« Reply #2 on: July 03, 2012, 07:37:42 AM »

All I check is
A) If shaders compiled succefully
B) If uniform_myTexture == -1, if yes, print the error that binding was unsuccesfull.
Logged

Nothing to do here
Christian Knudsen
Level 10
*****



View Profile WWW Email
« Reply #3 on: July 03, 2012, 07:45:16 AM »

Does glGetError return anything useful?
Logged

Laserbrain Studios
Currently working on Hidden Asset (TIGSource DevLog)
kamac
Level 10
*****


Notorious posts editor


View Profile Email
« Reply #4 on: July 03, 2012, 07:53:00 AM »

It seems it returns nothing. (Aka. nothing matches it)
Logged

Nothing to do here
Liosan
Level 2
**


View Profile
« Reply #5 on: July 03, 2012, 08:20:52 AM »

Everything bind succefully but not

uniform sampler2D mytexture;
uniform vec4 color;

which are inside my fragment shader... Those that are inside vertex shader bind correctly.
Effectievely your shader doesn't need them:
Code:
gl_FragColor = vec4(1.0,1.0,1.0,1.0);
So the GLSL compiler optimised it out; they don't exist anymore it the resulting compiled code. No wonder they can't be found.

Liosan
Logged

kamac
Level 10
*****


Notorious posts editor


View Profile Email
« Reply #6 on: July 03, 2012, 08:25:22 AM »

Eeeew you're right Liosan. What GLSL compiler does sucks  Crazy
I guess I will need to learn more about it  WTF
Logged

Nothing to do here
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic