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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:50:41+00:00 2026-05-21T19:50:41+00:00

I’m trying to draw a quad for a background (2D) using OpenGL 3.x+. Quads

  • 0

I’m trying to draw a quad for a background (2D) using OpenGL 3.x+. Quads are deprecated, so the goal is to use two triangles to make a rectangle that fills the screen. It’s working, but I’m not 100% clear on everything here.

  1. Setup

    GLuint positionBufferObject;
    GLfloat vertexPositions[] =
    {
        -1.0f, -1.0f, 0.0f, 1.0f,
        -1.0f,  1.0f, 0.0f, 1.0f,
         1.0f,  1.0f, 0.0f, 1.0f,
         1.0f, -1.0f, 0.0f, 1.0f,
        -1.0f, -1.0f, 0.0f, 1.0f,
    };
    glGenBuffers(1, &positionBufferObject);
    glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertexPositions), vertexPositions, GL_STATIC_DRAW);
    
    • I understand the vertexPositions, it’s an array of vertices.
    • glGenBuffers() is saying, I want 1 buffer and assign id to &positionBufferObject?
    • glBufferData() uploads the vertexPositions to the GPU’s memory; but how does it know were to upload it since I didn’t give it an ID?
  2. Draw

    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 5);
    glDisableVertexAttribArray(0);
    
    • glEnableVertexAttribArray() just says I’m going to be drawing with array 0?
    • glDrawArrays() – what if I want to draw two vertex arrays? How does it know which ones to render? It knows that from the above command?
    • Not sure what glVertexAttribPointer() does?
    • glDrawArrays() is clear.
  3. Clean up, I think this is right?

    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glDeleteBuffers(1, &positionBufferObject);
    

    I only do the setup/cleanup once.

Bonus points:

  • Is this the most effective way to render this? I read that I’m suppose to be submitting and be rendering in “batches” [?] since 3.x+ doesn’t do immediate mode any more. There is also only one array, so batches won’t help performance in this case, but if I had say “a very large number” of vertxArrays to draw, would it be the same process?
  • In setup they are storing the array id as positionBufferObject, but have it hardcoded in the rendering loop. Seems like it would get confusing after a dozen or so arrays, why isn’t it good practice to use the variable instead of hardcode it?
  • 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-21T19:50:41+00:00Added an answer on May 21, 2026 at 7:50 pm

    glGenBuffers(1, &positionBufferObject); says “make a vertex buffer object, and positionBufferObject is its ID.”

    glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject); says “positionBufferObject is now the current GL_ARRAY_BUFFER.”

    glBufferData(GL_ARRAY_BUFFER, sizeof(vertexPositions), vertexPositions, GL_STATIC_DRAW); says “upload vertexPositions to the ID currently bound to GL_ARRAY_BUFFER (which is positionBufferObject).”

    glEnableVertexAttribArray(0); says “vertex attribute array 0 is now available for use.”

    glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0); says “vertex attribute array 0 is to be interpreted as consisting of groups of 4 floats.”

    glDrawArrays(GL_TRIANGLE_STRIP, 0, 5); says “draw a triangle strip with five indices from every enabled array.”

    glDisableVertexAttribArray(0); says “we’re done for the time being with vertex attribute array 0.”

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker

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.