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 9220761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:25:27+00:00 2026-06-18T03:25:27+00:00

I just wanna do the basics… give the shaders information from my application. I

  • 0

I just wanna do the basics… give the shaders information from my application. I tried everything and nothing worked because I can never figure out what is new and what is deprecated in OpenGL

Vertex Shader:

#version 420 core

layout(location = 0) in vec2 p_rect;
layout(location = 1) in vec2 p_clipRect;

out vec2 texturePoint;

void main()
{
    gl_Position = vec4( p_rect, 0.0, 1.0 );
    texturePoint = p_clipRect;
}

Fragment Shader:

#version 420 core

uniform sampler2D p_texture;

in vec2 texturePoint;

out vec4 outColor;

void main()
{
    outColor = texture( p_texture, texturePoint );
}

OpenGL Code:

glActiveTexture( GL_TEXTURE0 );
glBindTexture( GL_TEXTURE_2D, texture );
GLint texture_id( glGetUniformLocation( programId, "p_texture" ) );
glUniform1i( texture_id, texture );

// Element
static const GLushort element[] = { 0, 1, 2, 3 };
GLuint element_id;
glGenBuffers( 1, &element_id );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, element_id );
glBufferData( GL_ELEMENT_ARRAY_BUFFER, sizeof( element ), element, GL_STATIC_DRAW );

// Vertex data
struct VertexInput
{
    GLfloat m_rect[ 8 ];
    GLfloat m_clipRect[ 8 ];
}
vertex;

// fill it up with data
GLfloat vertex_data[] =
{
    -1.0f, -1.0f,
    -1.0f,  1.0f,
    1.0f, -1.0f,
    1.0f,  1.0f,
    0.0f, 0.0f,
    0.0f, 1.0f,
    1.0f, 0.0f,
    1.0f, 1.0f,
};

memcpy( &vertex, &vertex_data, sizeof( vertex_data ) );

// VBO
GLuint vertex_id;
glGenBuffers( 1, &vertex_id );
glBindBuffer( GL_ARRAY_BUFFER, vertex_id );
glBufferData( GL_ARRAY_BUFFER, sizeof(vertex), &vertex, GL_STATIC_DRAW );

glEnableVertexAttribArray( 0 );
glEnableVertexAttribArray( 1 );
glVertexAttribPointer( 0, 2, GL_FLOAT, GL_TRUE, 0, (void*)offsetof( VertexInput, m_rect ) );
glVertexAttribPointer( 1, 2, GL_FLOAT, GL_TRUE, 0, (void*)offsetof( VertexInput, m_clipRect ) );

// render the VBO
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, element_id );
glDrawElements( GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, (void*)0 );

// clean it up ;-)
glDisableVertexAttribArray( 0 );
glDisableVertexAttribArray( 1 );

The weird thing:

Case 1: If programId is the actual program id, I get texture_id = 0 but no information gets to the shader… nothing happens…

Case 2: If programId is anything other than the actual program id, I get texture_id = -1 but my code RENDERS the image perfectly (WEARD).

The thing is that… I know it’s still wrong. I need to be able to give information to the shader and then render… I really don’t know how the case 2 is working, but the fact is that I need to give more information to the shaders, like other textures, MVP matrix and so son. I can’t do it. What is wrong? How do I give the correct value of my program id and get this information in the shader?

  • 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-18T03:25:28+00:00Added an answer on June 18, 2026 at 3:25 am
    glActiveTexture( GL_TEXTURE0 );
    ...
    glUniform1i( texture_id, texture );
    

    Try this instead:

    glActiveTexture( GL_TEXTURE0 + 0 );
    ...
    glUniform1i( texture_id, 0 );
    

    Sampler uniforms should be assigned the index of the desired texture unit, not the texture object ID.

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

Sidebar

Related Questions

I just wanna ask your opinion/suggestion on how to 'terminate' a running application/process is
i am using vb.net i just wanna ask if we can place a picture
I am new to LINQ and just wanna know; is there any application in
Just wanna ask this question. Can I use detailTextLabel in a Custom Cell? I
I just wanna learn why I can't static web methods in web services ?
I just wanna ask how can I make a form with two buttons that
I just wanna to substract one CSV-File from another one, but not if the
I just wanna display the contents of files from sdcard on emulator (as image
I just wanna grab with a regex the name from this text: Name: Paul
I just wanna know how i can save the value and the index for

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.