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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:17:34+00:00 2026-05-27T03:17:34+00:00

Warning: trying to learn OpenGL … I have drawn a square with the following

  • 0

Warning: trying to learn OpenGL …

I have drawn a square with the following code.

    static const GLfloat squareVertices[] = {
        -0.5f, -0.33f, 
         0.5f, -0.33f,
        -0.5f,  0.33f, 
         0.5f,  0.33f,
    };

...

        glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices);
        glEnableVertexAttribArray(ATTRIB_VERTEX);
...

        glVertexPointer(2, GL_FLOAT, 0, squareVertices);

So naturally, I thought to add two more vertices and get a hexagon. Instead, I have square that is folded like origami:

    static const GLfloat hexagonVertices[] = {
        -0.5f, -0.33f, 
        +0.0f, -0.66f, 
        +0.5f, -0.33f,
        +0.75f, +0.33f,
        -0.1f, +0.5f, 
        +0.25f, +0.33f,
    };

...

        glVertexAttribPointer(ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, hexagonVertices);
        glEnableVertexAttribArray(ATTRIB_VERTEX);

...

        glVertexPointer(3, GL_FLOAT, 0, hexagonVertices);

I have even tried changing the vertices to effect the shape. I can morph the square into a irregular, four-sided polygon, and I can skew the “hexagon”, but it is still just a folded piece of paper.

Can I do it this way?

What is the preferred alternate way?

  • 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-05-27T03:17:34+00:00Added an answer on May 27, 2026 at 3:17 am

    Your problem comes from sending a value of 3 in the second parameter of glVertexAttribPointer

    This tells opengl to use 3 coordinates per vertex instead of the two that you want. Since you have 12 floats, this becomes 4 vertices, hence the square.

    Edit: oh, and you need the first parameter of glVertexPointer to be 2 also.

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

Sidebar

Related Questions

When trying to compile the following code, I am getting a warning that line
Getting the following error when trying to start a session: Warning: session_start() [function.session-start]: Node
I'm trying to learn OpenGL with the redbook, and I'm now at the point
I have a mystery on my hands. I am trying to learn managed C++
I was just trying to learn and understand jQuery source code (so far with
I'm trying to learn to create and use static libraries in my Xcode projects
I am tyring to learn flex programming myself. Below code gives me a warning
I'm trying to learn how to profile perl memory. I have a very simple
I have trying to learn about resources. In VS when I create the project:
Encountered with the following warning when trying to access the page: Warning: mysql_fetch_array(): supplied

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.