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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:30:28+00:00 2026-05-26T02:30:28+00:00

Based on the information in Questions about glDrawRangeElements() and given the following items: struct

  • 0

Based on the information in Questions about glDrawRangeElements() and given the following items:

struct MyVertex
{
   GLfloat x, y, z;        //Vertex
};

const GLushort pindices[] = { 0, 1, 2, 3, 5, 4 };

struct MyVertex pvertex[6];
//VERTEX 0
pvertex[0].x = 0.0;
pvertex[0].y = 0.0;
pvertex[0].z = 0.0;
//VERTEX 1
pvertex[1].x = 1.0;
pvertex[1].y = 0.0;
pvertex[1].z = 0.0;
//VERTEX 2
pvertex[2].x = 0.0;
pvertex[2].y = 1.0;
pvertex[2].z = 0.0;
//VERTEX 3
pvertex[3].x = 0.0;
pvertex[3].y = 0.0;
pvertex[3].z = 0.0;
//VERTEX 4
pvertex[4].x = 1.0;
pvertex[4].y = 0.0;
pvertex[4].z = 0.0;
//VERTEX 5
pvertex[5].x = 0.0;
pvertex[5].y = -1.0;
pvertex[5].z = 0.0;

and the following initialization:

glGenBuffers(1, &VertexVBOID);
glBindBuffer(GL_ARRAY_BUFFER, VertexVBOID);
glBufferData(GL_ARRAY_BUFFER, sizeof(struct MyVertex)*3, &pvertex[0].x, GL_STATIC_DRAW);
glVertexPointer(3, GL_FLOAT, sizeof(struct MyVertex), BUFFER_OFFSET(0));

glGenBuffers(1, &IndexVBOID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexVBOID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort)*3, pindices, GL_STATIC_DRAW);

glEnableClientState(GL_VERTEX_ARRAY);

the following calls:

glDrawRangeElements(GL_TRIANGLES, 0, 2, 3, GL_UNSIGNED_SHORT, (const GLvoid*) pindices);
glDrawRangeElements(GL_TRIANGLES, 3, 5, 3, GL_UNSIGNED_SHORT, (const GLvoid*) pindices+3);

should draw two triangles. However, I get an EXE_BAD_ACCESS. If I use pindices[0] in glDrawRangeElements; I get the triangle defined by the first three indices. Using pindices[3] in the second call to glDrawRangeElements doesn’t result in anything being drawn and I don’t get any OpenGl errors. At no time does the second glDrawRangeElements call draw the inverted triangle defined by the final three vertices. I feel like I’m missing something fundamental regarding the use of pointers here, but I haven’t been able to figure it out yet. Thoughts?

  • 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-26T02:30:29+00:00Added an answer on May 26, 2026 at 2:30 am

    Your problems are not directly related to glDrawRangeElements, but to incorrect use of VBOs.

    First of all, when using VBOs (or more precise, when binding a VBO to GL_ELEMENT_ARRAY_BUFFER), the index pointer argument to glDraw... is interpreted as a byte offset into the buffer bound to the GL_ELEMENT_ARRAY_BUFFER binding point (the index buffer), similar to how the GL_ARRAY_BUFFER affects the array argument to glVertexPointer. Therefore the bad access. So replace (const GLvoid*)pindices with 0 in the first glDrawRangeElements call. The second call is wrong anyway, as you cannot do pointer arithmetic on a void pointer (it shouldn’t even compile, what size should it be increased by? bytes? shorts?). So in the second call use (const GLushort*)0+3 to gain a byte offset to the 4th index in the index buffer.

    Second, your buffers only contain half of the needed data, as you use sizeof(...)*3 in both glBufferData calls but your arrays actually contain 6 elements.

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

Sidebar

Related Questions

I have some questions about the :visited pseudo-class: Based on what do browsers decide
Based on information in Chapter 7 of 3D Programming For Windows (Charles Petzold) ,
I often need to display information based on or influenced by a user's actual
I want to change the title showing in a page based on information I
I have multiple linq queries for searching a database of information based on a
My script puts together a set of htaccess rules based on information passed into
I'd like to have a page in php that normally displays information based on
I'm working on a C# XNA project that requires me to display information based
I'm trying to modify the decimal-format of a stylesheet based on certain information of
I'm looking for a way to sort an array, based on the information in

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.