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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:31:17+00:00 2026-06-14T03:31:17+00:00

I am trying to render a model in openGL 4 using the glDrawElements/Arrays function.

  • 0

I am trying to render a model in openGL 4 using the glDrawElements/Arrays function. I am currently reading in files with vertex data and indices for polygons. I cannot get anyting to display on screen though except the axes im using for reference. I have used this general approach a bunch of times with success. I dont know what I could be doing wrong and have been stuck for almost a day.

This is where I buffer my data

// get position of "in vec4 vPosition;" from shader program
// displays axes properly
vPosition = glGetAttribLocation( program, "vPosition" );

// create buffers
glGenVertexArrays(2, vao);
glGenBuffers( 3, vbo );

// here I bind vao[0] and vbo[0] then buffer
// a set of XYZ axes which display correctly

// buffer model
glBindVertexArray( vao[1] );
glBindBuffer( GL_ARRAY_BUFFER, vbo[1] );
glBufferData( GL_ARRAY_BUFFER, sizeof(board->verts),
                board->verts, GL_STATIC_DRAW );

glEnableVertexAttribArray( vPosition );
glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE, 0,
                        BUFFER_OFFSET(0));

glBindBuffer( GL_ELEMENT_ARRAY_BUFFER , vbo[2] );
glBufferData(
        GL_ELEMENT_ARRAY_BUFFER,
        sizeof(board->indices),
        board->indices.data(),
        GL_STATIC_DRAW);

fyi board is a model of a surfboard in which the vertices and indices for glDrawElements are read in. These vertices and indices are printed out correctly if the following code is included just above the call to glBufferData

for( int i = 0; i < board->numVerts; i++ ){
    std::cerr << i << ":  "<<board->verts[i].x << " "<<board->verts[i].y<<" "<<
            board->verts[i].z << " " << board->verts[i].w << std::endl;
}

the same goes for the indices if a similar print loop is put in. Here is where I attempt to draw the model:

void draw_model(){

    glUniform4fv( color_loc, 1, glm::value_ptr(blue));
    glBindVertexArray( vao[1] );

    glDrawArrays( GL_LINE_STRIP, 0, 600 );

    //glDrawElements(
    //  GL_LINES,
    //  board->indices.size(),
    //  GL_UNSIGNED_INT,
    //  NULL
    //);

}

the call to DrawElements (commented out) does not display anything. the call to DrawArrays was a troubleshooting effort to see if I was just using DrawElements incorrectly (i have only used drawArrays in the past). board is defined as model3d *board. here is its class

class model3d{
public:
    glm::vec4 *verts;
    std::vector<int> indices;
    int numVerts;
    int numPolys;
    model3d( const char*, const char* );
private:
    void load_coords( const char* );
    void load_polys( const char* );
};

why does my data not seem to buffer?

  • 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-14T03:31:18+00:00Added an answer on June 14, 2026 at 3:31 am

    Don’t use sizeof(board->verts) as it’ll only return the size of the pointer.

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

Sidebar

Related Questions

Currently I am trying to render a .obj model that I loaded into vectors.
I am trying to render a very complex model using json file. The size
Im trying to render a non power of 2 texture using a model class
I am trying to render 2D (flat) sprites in a 3D environment using OpenGL
I have a model property I'm trying to render using an EditorFor template, and
I am using OpenGL to render a model of an object that is rotationally-symmetric
I am trying to render a model in Direct3D using DrawIndexedPrimitives . However, I
I have a User model that has many posts. Im trying to render the
I've been trying to render a webpage using the Adobe Flex / Flash builder
I am trying to add a file to a model using qqfile (though that

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.