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

  • Home
  • SEARCH
  • 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 9051545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:55:52+00:00 2026-06-16T12:55:52+00:00

I’m currently trying to make a very simple snake game and have some problem

  • 0

I’m currently trying to make a very simple snake game and have some problem creating the snake square. Right now I am creating the squares by creating 2 triangles. I have created the grid where the snake should be moving like this:
enter image description here

The color of the squares were actually yellow in the beginning. Then I tried to create the snake with the color red. But all my squares turned red.

I create the snake like this:

void drawSnake()
{
    mat4 modelView;

    modelView = Translate(1,0,0);
    glUniformMatrix4fv(modelViewUniform, 1, GL_TRUE, modelView);
    GLuint indices2[3] = {0,1,2}; //, 0, 5, 1, 0};

    glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, indices2);

    modelView = Translate(1, 0, 0);
    glUniformMatrix4fv(modelViewUniform, 1, GL_TRUE, modelView);
    GLuint indices6[3] = {4,3,2}; //, 0, 5, 1, 0};
    glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, indices6);
    //vec2 blockCoordinate = vec2(-t + 1, t - 1);
    //blockCol[i] = blockCoordinate;
}

The colors defined here:

void loadGeometry() {
    vec3 color(1.0f, 1.0f, 0.0f);
    Vertex rectangleData[rectangleSize] = {
        { vec2( -1.0, -1.0 ), color },
        { vec2( 1.0, -1.0 ), color },
        { vec2( 1.0,  1.0 ), color },
        { vec2( -1.0,  1.0 ), color },
        { vec2(-1.0, -1.0 ), color }
    };
    shapeVertexArrayBuffer = loadBufferData(rectangleData, rectangleSize);

    vec3 color1(1.0f, 0.0f, 0.0f);
    Vertex rectangleData1[rectangleSize] = {
        { vec2( -1.0, -1.0 ), color1 },
        { vec2( 1.0, -1.0 ), color1 },
        { vec2( 1.0,  1.0 ), color1 },
        { vec2( -1.0,  1.0 ), color1 },
        { vec2(-1.0, -1.0 ), color1 }
    };
    shapeSnakeArrayBuffer = loadBufferData(rectangleData1, rectangleSize);
}

So the question is why all my squares turned red when I obviously load the buffer data with another color?

I draw them like this in the display():

void display() {    
    glClearColor(0.0, 0.0, 0.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);

    glUseProgram(shaderProgram);

    mat4 projection = Ortho2D(-15.0f, 15.0f, -15.0f, 15.0f);
    glUniformMatrix4fv(projectionUniform, 1, GL_TRUE, projection);

    glBindVertexArray(shapeVertexArrayBuffer);
    glBindVertexArray(shapeSnakeArrayBuffer);

    drawBlock();
    drawSnake();
    glutSwapBuffers();
}
  • 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-16T12:55:53+00:00Added an answer on June 16, 2026 at 12:55 pm
    glBindVertexArray(shapeVertexArrayBuffer);
    glBindVertexArray(shapeSnakeArrayBuffer);
    
    drawBlock();
    drawSnake();
    

    You seem to have some ordering problems here. Presumably the shapeVertexArrayBuffer (note: there’s no such thing as a “vertex array buffer”. Those are supposed to be vertex array objects; if loadBufferData doesn’t return a VAO, then you have more problems) is meant for drawing blocks, and the shapeSnakeArrayBuffer is meant for drawing the snake.

    You can only have one VAO active at a time. glBindVertexArray sets the given vertex array object to be what is used for all rendering commands after it. Since the last one you used was shapeSnakeArrayBuffer, that will be the VAO used for all rendering commands in drawBlock just as well as for drawSnake.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have a jquery bug and I've been looking for hours now, I can't
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have been unable to fix a problem with Java Unicode and encoding. The
I am trying to loop through a bunch of documents I have to put
I am currently running into a problem where an element is coming back from
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
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

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.