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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:10:19+00:00 2026-06-08T13:10:19+00:00

I’m working on a 2D engine in C++ at the moment. I’ve run into

  • 0

I’m working on a 2D engine in C++ at the moment.

I’ve run into a problem which I seem to believe I’ve come up against once before, but have since forgotten how I fixed it.

The engine is cross platform ( Win, OSX, Linux ) and to accomplish this I am using GLFW as a base.

When doing the normal texturing thing I end up with this :

http://tinypic.com/r/263ec6o/6

As you can see the texturing isn’t right ( as the image is supposed to be a simple Image of me ).

Using geDebugger I can confirm that the image being buffered to the GPU is correct, but some how it is ending up as you see in the Image.

I’ll include some cuts of relevant code below, but should you want more info feel free to ask.

-Buffer Generation Code

glGenVertexArrays( 1, &_vao );
// Generate Buffers and so on.
glBindVertexArray( _vao );

glGenBuffers( 1, &_vboVertices );
glBindBuffer( GL_ARRAY_BUFFER, _vboVertices );
glBufferData( GL_ARRAY_BUFFER, sizeof(GLfloat) * 3 * _numVertices, _vertices, GL_STATIC_DRAW );

glGenBuffers( 1, &_vboTexCoords );
glBindBuffer( GL_ARRAY_BUFFER, _vboTexCoords );
glBufferData( GL_ARRAY_BUFFER, sizeof(GLfloat) * 2 * _numVertices, _texCoords, GL_STATIC_DRAW );

glGenBuffers( 1, &_vboIndices );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, _vboIndices );
glBufferData( GL_ELEMENT_ARRAY_BUFFER, sizeof(GLint) * _numIndices, _indices, GL_STATIC_DRAW );

-Render Code

glm::mat4 modelViewProjMatrix = projMatrix * viewMatrix * modelMatrix;

ShaderResource * shader = ShaderManager::GetInstance()->GetShader( _shaderName.c_str() );
TextureResource * texture = TextureManager::GetInstance()->GetTexture( _textureName.c_str() );

shader->BindShader();

// Bind VAO
glBindVertexArray( _vao );

// Bind all VBO's
glBindBuffer( GL_ARRAY_BUFFER, _vboVertices );
GLint posLocation = shader->GetAttribLocation("in_position");
glVertexAttribPointer( posLocation, 3, GL_FLOAT, GL_FALSE, 0, (void*)0 );
GLint texCoordLocation = shader->GetAttribLocation("in_texCoord");
glVertexAttribPointer( texCoordLocation, 2, GL_FLOAT, GL_FALSE, 0, (void*)0 );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, _vboIndices );

// Enable VBO Pointers
glEnableVertexAttribArray( posLocation );
glEnableVertexAttribArray( texCoordLocation );

// Find and assign Uniforms
GLint MVPMatrixLocation = shader->GetUniformLocation("in_MVPMatrix");
GLint colourLocation = shader->GetUniformLocation("in_colour");
GLint textureLocation = shader->GetUniformLocation("texMap");

glUniformMatrix4fv( MVPMatrixLocation, 1, GL_FALSE, glm::value_ptr( modelViewProjMatrix ) );
glUniform4fv( colourLocation, 1, glm::value_ptr( _colour ) );

// Texture Uniform
if( texture != 0 )
{
    glActiveTexture( GL_TEXTURE0 );
    glUniform1i( textureLocation, 0 );
    glBindTexture( GL_TEXTURE_2D, texture->GetTextureId() );
}

glDrawElements( GL_TRIANGLES, _numIndices, GL_UNSIGNED_INT, (void*) 0 );

glDisableVertexAttribArray( posLocation );
glDisableVertexAttribArray( texCoordLocation );

shader->UnbindShader();

glBindVertexArray( 0 );

-Vert Shader

#version 150

in vec3 in_position;
in vec2 in_texCoord;

out vec4 out_colour;
smooth out vec2 out_texCoord;

uniform vec4 in_colour;
uniform mat4 in_MVPMatrix;

void main()
{
out_colour = in_colour;
out_texCoord = in_texCoord;

    gl_Position = in_MVPMatrix * vec4( in_position, 1.0 );
}

-Frag Shader

#version 150

in vec4 out_colour;
smooth in vec2 out_texCoord;

out vec4 fragColor;

uniform sampler2D texMap;

void main()
{
    vec4 diffuseTexel = texture2D( texMap, out_texCoord );

    fragColor = out_colour * diffuseTexel;
} 
  • 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-08T13:10:21+00:00Added an answer on June 8, 2026 at 1:10 pm
    glVertexAttribPointer( posLocation, 3, GL_FLOAT, GL_FALSE, 0, (void*)0 );
    glVertexAttribPointer( texCoordLocation, 2, GL_FLOAT, GL_FALSE, 0, (void*)0 );
    

    This means that both the positions and texture coordinates come from the same locations in the buffer. That they overlap.

    You seem to want them to come from different buffer objects. That means you have to bind a new buffer to GL_ARRAY_BUFFER between your first and second glVertexAttribPointer calls.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I would like to run a str_replace or preg_replace which looks for certain words
I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I want to count how many characters a certain string has in PHP, but
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
this is what i have right now Drawing an RSS feed into the php,

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.