Jump to content
  • Advertisement
Sign in to follow this  
DominicHughes

having troubles getting my uniform variable in my vertex shader to work

This topic is 2343 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all trying to get my uniform variable to work in my vertex shader but it won't change the position of the triangle in x axis by 10units even when I use this code below in my main.cpp file inside the loadprogram function which looks like this



//Load Shader Function
GLuint LoadProgram(const char * vertex_file_path, const char * Fragment_file_path){

GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);

//READ THE VERTEX SHADER CODE
string VertexShaderCode;
ifstream VertexShaderStream(vertex_file_path, std::ios::in);
if(VertexShaderStream.is_open())
{
string Line = "";
while(getline(VertexShaderStream, Line))
VertexShaderCode += "\n" + Line;
VertexShaderStream.close();
}

//READ THE FRAGMENT SHADER CODE
string FragmentShaderCode;
ifstream FragmentShaderStream(Fragment_file_path, std::ios::in);
if(FragmentShaderStream.is_open())
{

string Line = "";
while(getline(FragmentShaderStream, Line))
FragmentShaderCode += "\n" + Line;
FragmentShaderStream.close();

}
GLint Result = GL_FALSE;
int InfoLogLength;
//Compile Vertex Shader
printf("Compiling Shader : %s\n", vertex_file_path);
char const * VertexSourcePointer = VertexShaderCode.c_str();
glShaderSource(VertexShaderID, 1, &VertexSourcePointer, NULL);
glCompileShader(VertexShaderID);
//Check Vertex Shader
glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
vector<char> VertexShaderErrorMessage(InfoLogLength);
glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
fprintf(stdout, "%s\n", &VertexShaderErrorMessage[0]);

//Compile Fragment Shader
printf("Compiling Shader : %s\n", Fragment_file_path);
char const * FragmentSourcePointer = FragmentShaderCode.c_str();
glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer, NULL);
glCompileShader(FragmentShaderID);
//Check Fragment Shader
glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
vector<char> FragmentShaderErrorMessage(InfoLogLength + 1);
glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
fprintf(stdout, "%s\n", &FragmentShaderErrorMessage[0]);
//Link The Program
fprintf(stdout, "Linking Program\n");
GLuint ProgramID = glCreateProgram();
glAttachShader(ProgramID, VertexShaderID);
glAttachShader(ProgramID, FragmentShaderID);
glLinkProgram(ProgramID);
//Check The Program
glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
vector<char> ProgramErrorMessage( max(InfoLogLength, int(1)) );
fprintf(stdout, "%s\n", &ProgramErrorMessage[0]);

//Delete Shader
glDeleteShader(VertexShaderID);
glDeleteShader(FragmentShaderID);



int my_vec3_location = glGetUniformLocation(ProgramID, "translations");



glUniform3f(my_vec3_location, 10, 1, 0);

return ProgramID;



glUseProgram(ProgramID);



}






here is my vertex shader code

attribute vec4 position;
varying vec2 texcoord;
uniform vec3 translations;
void main(void)
{
translations.xyz;
// To Put The Vertex in View?
gl_Position = vec4(position.xyz + translations.xyz, 1.0);


}




thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!