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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:41:24+00:00 2026-06-08T07:41:24+00:00

I am trying to get my very simple shader working with my current OpenGL

  • 0

I am trying to get my very simple shader working with my current OpenGL set up. I am using a shader manager and upon loading the shaders, all the output says they have loaded correctly.

Here is my data:

static const GLfloat g_vertex_buffer_data[] = {
    -1.0f, -1.0f, 0.0f,
    1.0f, -1.0f, 0.0f,
    0.0f,  1.0f, 0.0f,
};

Here is where i set up my buffer:

// This will identify our vertex buffer
GLuint vertexbuffer;

// Generate 1 buffer, put the resulting identifier in vertexbuffer
glGenBuffers(1, &vertexbuffer);

// The following commands will talk about our 'vertexbuffer' buffer
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);

// Give our vertices to OpenGL.
glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);

Here is my declaration of my shader using a tested and working shader loader:

Shader shader;
shader.loadFromFile(VERTEX_SHADER, resourcePath() + "tri.vert");
shader.loadFromFile(FRAGMENT_SHADER, resourcePath() + "tri.frag");
shader.createAndLinkProgram();
shader.use();
shader.addAttribute("position");
shader.unUse();

The attributes for this shader are then stored in a map. This is the rendering call:

shader.use();

    glEnableVertexAttribArray(shader["position"]);
    glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
    glVertexAttribPointer(
                          shader["position"], // attribute 0. No particular reason for 0, but must match the layout in the shader.
                          3,                  // size
                          GL_FLOAT,           // type
                          GL_FALSE,           // normalized?
                          0,                  // stride
                          (void*)0            // array buffer offset
                          );

    // Draw the triangle !
    glDrawArrays(GL_TRIANGLES, 0, 3); // Starting from vertex 0; 3 vertices total -> 1 triangle

    glDisableVertexAttribArray(shader["position"]);

    shader.unUse();

I then swap the buffers. I tried with an old GL_TRIANGLES fixed pipeline drawing and it worked fine.

Here is my vertex shader:

#version 330
layout(location = 0) in vec3 position;

void main()
{
gl_Position.xyz = position;
} 

Here is my fragment shader:

out vec3 color;

main()
{
color = vec3(1,0,0);
}

It is supposed to simply draw a red triangle. When I draw using intermediate mode, it renders fine. I am running Xcode on Mac OSX 10.7.4.

  • 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-08T07:41:25+00:00Added an answer on June 8, 2026 at 7:41 am

    gl_Position.xyz = position;

    And what is the W coordinate? It’s kind of important not to leave it undefined. If you want it to be 1.0, you need to set it to be that:

    gl_Position = vec4(position, 1.0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Embedded Jetty I am trying to get a very simple servlet to forward
I am having difficulty trying to get a very simple scenario working with PRISM
I have a very simple properties file test I am trying to get working:
I am trying to get jscrollpane working on a very simple page, but for
I am trying to get a very simple program to compile while using functions
I'm trying to get a very simple Spring @mvc app to work and I'm
I'm trying to compile a very simple c++ code and get a linking error
I'm trying to make a very simple OSGi test but I can't get it
Here's a very simple example of what I'm trying to get around: class Test(object):
I have a very simple UserControl as shown below. I'm trying to get the

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.