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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:22:23+00:00 2026-06-16T02:22:23+00:00

So, I’m trying to study vbo and just do some examples, but opengl is

  • 0

So, I’m trying to study vbo and just do some examples, but opengl is killing me. I’ve been four hours trying to do this code work, but I dont have a clue why this dont work.
I was trying to draw 4 squares with different colors.
But if I try to draw using GL_POINTS i only see 4 points in the screen, and is supposed to be 9 points. If I try using GL_QUADS it simply don’t draw nothing.
The interesting is that when I change this line:

glDrawElements(GL_POINTS, 16, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0));

to this:

glDrawElements(GL_POINTS, 64, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0));

Opengl draw the 9 dots, but only that, GL_QUADS dont work.
Please, someone give me a light on this problem, it’s killing me!!
The complete code is here:

#define GL_GLEXT_PROTOTYPES
#include<GL/glut.h>
#include<iostream>
using namespace std;

#define BUFFER_OFFSET(offset) ((GLfloat*) NULL + offset)

#define VERTICES 0
#define INDICES 1
#define NUM_BUFFERS 2

void init_2(){

GLuint buffers[NUM_BUFFERS];

GLfloat vertices[][3]= { 
                {0.0, 0.0,  0.0},
                {0.0, 40.0, 0.0},
                {0.0, 80.0, 0.0},
                {40.0, 0.0, 0.0},
                {40.0, 40.0, 0.0},
                {40.0, 80.0, 0.0},
                {80.0, 0.0, 0.0},
                {80.0, 40.0, 0.0},
                {80.0, 80.0, 0.0}
              };

GLuint indices[][4] = {
              {0, 1, 4, 3}, 
              {1, 2, 5, 4}, 
              {3, 4, 7, 6}, 
              {4, 5, 8, 7}
            };    

glGenBuffers(NUM_BUFFERS, buffers);

glBindBuffer(GL_ARRAY_BUFFER, buffers[VERTICES]);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));

glEnableClientState(GL_VERTEX_ARRAY);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[INDICES]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
}

void display(void){  

glPushMatrix();         
glDrawElements(GL_POINTS, 16, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0));
glPopMatrix();
glutSwapBuffers();
}

void init() 
{
  glClearColor(0.0, 0.0, 0.0, 0.0);
  gluOrtho2D((GLdouble) -1.0, (GLdouble) 90.0, (GLdouble) -1.0, (GLdouble) 90.0);  
  init2();
}

int main(int argv, char** argc) {

  glutInit(&argv, argc);
  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
  glutInitWindowSize(500,500);
  glutInitWindowPosition(100,100); 
  glutCreateWindow("myCode.cpp");
  init();
  glutDisplayFunc(display);
  glutMainLoop();

  return 0;  
}
  • 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-16T02:22:24+00:00Added an answer on June 16, 2026 at 2:22 am

    Here’s the problem:

    GLuint indices[][4] = {
    ...
    glDrawElements(GL_POINTS, 16, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0));
    

    You declare GLuint indices, but then tell glDrawElements that you’re giving it bytes.

    GLuint is a 32-bit type, so there are 4 bytes for each. As your index data is very small, each 32-bit value has only data in the bottom byte, leaving the rest as zero.

    So in the first 16 bytes, which are the first 4 GLuints, there are only 4 discrete values, so you see 4 points. If you try 64 (which is 16 * 4), you will see all 9 points. However these points are mixed in with a lot of zeros, so when you try to render as GL_QUADS, nothing will be drawn.

    • 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
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.