Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9193699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:13:33+00:00 2026-06-17T21:13:33+00:00

After working with one program and one set of vertex / fragment shaders, I

  • 0

After working with one program and one set of vertex / fragment shaders, I need to use more programs, so my initial setup function that didn’t have any parameters wasn’t sufficient anymore.

To my setup function, I pass the shader_program and the two shader sources. When I try to use the program in my display method, the GLuint program handle is zero. What I currently don’t understand is why it all worked when I used fixed sources for my shaders. Could it be a C++ program and I’m passing the parameters in the wrong way? I’m not getting any error messages but nothing is rendered on screen.

Here’s the code I use to call the shader setup function and the function itself:

// Variables
GLuint shader_program;

const GLchar *vertex_shader =   
"#version 330\n"
""
"layout (location = 0) in vec3 in_position;"
...
"";

// In my main function, I call this to set up the shaders
installShaders(shader_program, vertex_shader, fragment_shader);

// SET-UP-METHOD
void installShaders(GLuint program_handle, const GLchar *vertex_shader_source, const GLchar *fragment_shader_source)
{
// Handles for the shader objects
GLuint   vertex_shader_name;
GLuint fragment_shader_name;

// Status values 
GLint   vertex_shader_compiled;
GLint fragment_shader_compiled;
GLint      successfully_linked;

// Generate shader names
vertex_shader_name   = glCreateShader(GL_VERTEX_SHADER);
fragment_shader_name = glCreateShader(GL_FRAGMENT_SHADER);

// Specify the sources for the shaders
glShaderSource(  vertex_shader_name, 1, (const GLchar**)&vertex_shader_source  , NULL);
glShaderSource(fragment_shader_name, 1, (const GLchar**)&fragment_shader_source, NULL);

// Compile Vertex shader and check for errors
glCompileShader(vertex_shader_name);
glGetShaderiv(vertex_shader_name, GL_COMPILE_STATUS, &vertex_shader_compiled);
printShaderInfoLog(vertex_shader_name);

// Compile Fragment shader and check for errors
glCompileShader(fragment_shader_name);
glGetShaderiv(fragment_shader_name, GL_COMPILE_STATUS, &fragment_shader_compiled);
printShaderInfoLog(fragment_shader_name);

// Exit if the shaders couldn't be compiled correctly
if(!vertex_shader_compiled || !fragment_shader_compiled)
{
    printf("Shaders were not compiled correctly!\n");
    exit(EXIT_FAILURE);
}

// Generate program name
program_handle = glCreateProgram();

// Attach shaders to the program
glAttachShader(program_handle, vertex_shader_name);
glAttachShader(program_handle, fragment_shader_name);

// Link program and check for errors
glLinkProgram(program_handle);
glGetProgramiv(program_handle, GL_LINK_STATUS, &successfully_linked);
printProgramInfoLog(program_handle);

// Exit if the program couldn't be linked correctly
if(!successfully_linked)
{
    printf("Program was not linked correctly!\n");
    exit(EXIT_FAILURE);
}

// Set up initial values of uniform variables
glUseProgram(program_handle);

location_projectionMatrix = glGetUniformLocation(program_handle, "myProjectionMatrix");
printf("Location of the uniform -->myProjectionMatrix<--- : %i\n", location_projectionMatrix);
projectionMatrix = glm::mat4(1.0f);
glUniformMatrix4fv(location_projectionMatrix, 1, GL_FALSE, glm::value_ptr(projectionMatrix));

location_modelViewMatrix = glGetUniformLocation(program_handle, "myModelViewMatrix");
printf("Location of the uniform -->myModelViewMatrix<--- : %i\n", location_modelViewMatrix);
modelViewMatrix = glm::mat4(1.0f);
glUniformMatrix4fv(location_modelViewMatrix, 1, GL_FALSE, glm::value_ptr(modelViewMatrix));

glUseProgram(0);

// Everything worked
printf("Shaders were set up correctly!\n");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:13:34+00:00Added an answer on June 17, 2026 at 9:13 pm

    The issue is that the variable you store the GLSL shader program name (the value returned from glCreateShader) into is passed-by-value into the routine. As such, its value is lost when the function returns. Passing the value in by reference (as either a pointer or as a C++ reference), then the value will be preserved when the function exits, and you’ll be able to reference the shader in other parts of your application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After many hair-pulling frustrations I've finally got one version of the PerlMagick module working
I wrote a simple test program for opencv to see if it's working after
Background: I'm working on a GUI from Hell program. Problem: I need to change
I have a program that is supposed to run a set of other programs
I'm working on a concordance program and currently working on the getContext function. I
After working on some test code for open ID authentication, I had a break
After working in Eclipse for the past 3 years and memorizing all of the
After working with ASP.Net MVC, it has me thinking about Rails. I worked with
After working with the .NET GDI+ Rectangle object, I've noticed that if I create
I can't believe I'm back to this after working with WPF for 3 months

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.