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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:04:41+00:00 2026-06-12T14:04:41+00:00

I’m learning OpenGL 3.3, using some tutorials (http://opengl-tutorial.org). In the tutorial I’m using, there

  • 0

I’m learning OpenGL 3.3, using some tutorials (http://opengl-tutorial.org). In the tutorial I’m using, there is a vertex shader which does the following:

Tutorial Shader source

#version 330 core

// Input vertex data, different for all executions of this shader.
layout(location = 0) in vec3 vertexPosition_modelspace;

// Values that stay constant for the whole mesh.
uniform mat4 MVP;

void main(){

    // Output position of the vertex, in clip space : MVP * position
    gl_Position =  MVP * vec4(vertexPosition_modelspace,1);

}

Yet, when I try to emulate the same behavior in my application, I get the following:

error: implicit cast from "vec4" to "vec3".

After seeing this, I wasn’t sure if it was because I was using 4.2 version shaders as opposed to 3.3, so changed everything to match what the author had been using, still receiving the same error afterward.

So, I changed my shader to do this:

My (latest) Source

#version 330 core

layout(location = 0) in vec3 vertexPosition_modelspace;

uniform mat4 MVP;

void main()
{
    vec4 a = vec4(vertexPosition_modelspace, 1);    

    gl_Position.xyz = MVP * a;
}

Which, of course, still produces the same error.

Does anyone know why this is the case, as well as what a solution might be to this? I’m not sure if it could be my calling code (which I’ve posted, just in case).


Calling Code

static const GLfloat T_VERTEX_BUF_DATA[] = 
{
    // x, y z
    -1.0f, -1.0f, 0.0f,
     1.0f, -1.0f, 0.0f,
     0.0f, 1.0f, 0.0f
};

static const GLushort T_ELEMENT_BUF_DATA[] = 
{ 0, 1, 2 };

void TriangleDemo::Run(void)
{
    glClear(GL_COLOR_BUFFER_BIT);

    GLuint matrixID = glGetUniformLocation(mProgramID, "MVP");

    glUseProgram(mProgramID);

    glUniformMatrix4fv(matrixID, 1, GL_FALSE, &mMVP[0][0]); // This sends our transformation to the MVP uniform matrix, in the currently bound vertex shader 

    const GLuint vertexShaderID = 0;

    glEnableVertexAttribArray(vertexShaderID);
    glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
    glVertexAttribPointer(
        vertexShaderID, // Specify the ID of the shader to point to (in this case, the shader is built in to GL, which will just produce a white triangle)
        3,              // Specify the number of indices per vertex in the vertex buffer  
        GL_FLOAT,       // Type of value the vertex buffer is holding as data
        GL_FALSE,       // Normalized? 
        0,              // Amount of stride
        (void*)0 );     // Offset within the array buffer

    glDrawArrays(GL_TRIANGLES, 0, 3); //0 => start index of the buffer, 3 => number of vertices

    glDisableVertexAttribArray(vertexShaderID);
}

void TriangleDemo::Initialize(void)
{
    glGenVertexArrays(1, &mVertexArrayID);

    glBindVertexArray(mVertexArrayID);

    glGenBuffers(1, &mVertexBuffer);

    glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);

    glBufferData(GL_ARRAY_BUFFER, sizeof(T_VERTEX_BUF_DATA), T_VERTEX_BUF_DATA, GL_STATIC_DRAW );

    mProgramID = LoadShaders("v_Triangle", "f_Triangle");

    glm::mat4 projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f); // field of view, aspect ratio (4:3), 0.1 units near, to 100 units far

    glm::mat4 view  = glm::lookAt(
                                glm::vec3(4, 3, 3), // Camera is at (4, 3, 3) in world space
                                glm::vec3(0, 0, 0), // and looks at the origin
                                glm::vec3(0, 1, 0)  // this is the up vector - the head of the camera is facing upwards. We'd use (0, -1, 0) to look upside down
                            );

    glm::mat4 model = glm::mat4(1.0f); // set model matrix to identity matrix, meaning the model will be at the origin

    mMVP            = projection * view * model;

}

Notes

  • I’m in Visual Studio 2012
  • I’m using Shader Maker for the GLSL editing
  • 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-12T14:04:42+00:00Added an answer on June 12, 2026 at 2:04 pm

    I can’t say what’s wrong with the tutorial code.

    In “My latest source” though, there’s

    gl_Position.xyz = MVP * a;
    

    which looks weird because you’re assigning a vec4 to a vec3.


    EDIT

    I can’t reproduce your problem.

    I have used a trivial fragment shader for testing…

    #version 330 core
    
    void main()
    {
    }
    

    Testing “Tutorial Shader source”:

    3.3.11762 Core Profile Context
    Log: Vertex shader was successfully compiled to run on hardware.
    
    Log: Fragment shader was successfully compiled to run on hardware.
    
    Log: Vertex shader(s) linked, fragment shader(s) linked.
    

    Testing “My latest source”:

    3.3.11762 Core Profile Context
    Log: Vertex shader was successfully compiled to run on hardware.
     WARNING: 0:11: warning(#402) Implicit truncation of vector from size 4 to size 3.
    
    Log: Fragment shader was successfully compiled to run on hardware.
    
    Log: Vertex shader(s) linked, fragment shader(s) linked.
    

    And the warning goes away after replacing gl_Position.xyz with gl_Position.


    What’s your setup? Do you have a correct version of OpenGL context? Is glGetError() silent?

    Finally, are your GPU drivers up-to-date?

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

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.