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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:45:59+00:00 2026-05-28T18:45:59+00:00

I’m trying to model an object described in a WRL (VRML) file using OpenGL.

  • 0

I’m trying to model an object described in a WRL (VRML) file using OpenGL.

I’m not really concerned with parsing the file, I figure that part will be fairly straight forward. At this stage I am just trying to hard-code in a vertex array and index array so that I can get a good understanding of how this works so that I can generalise for any WRL input file.

I’m trying a basic box (rectangular prism) model first. I currently have this vertex array:

GLfloat vertices[] = {
     -0.200000, -0.025000, -0.050000,
     -0.200000, -0.025000, 0.050000, 
     -0.200000, 0.025000, -0.050000, 
     -0.200000, 0.025000, 0.050000, 
      0.200000, -0.025000, -0.050000,
      0.200000, -0.025000, 0.050000, 
      0.200000, 0.025000, -0.050000, 
      0.200000, 0.025000, 0.050000
};

and this index array:

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

which came directly from the WRL file Coordinate3 {point []} and IndexedFaceSet {coordIndex []}.

I then enable vertex array functionality by calling:

glEnableClientState(GL_VERTEX_ARRAY);

and set up the glVertexPointer:

glVertexPointer(3, GL_FLOAT, 0, vertices);

finally I use the glDrawElements function to draw the box:

glDrawElements(GL_POLYGON, 24, GL_UNSIGNED_BYTE, indices);

and then deactivate vertex array functionality:

glDisableClientState(GL_VERTEX_ARRAY);

So after this, I would expect a box to be drawn, and when I use glDrawElements(GL_POINTS, 24, GL_UNSIGNED_BYTE, indices); it shows the 8 vertices as epected in what, if the correct vertices were joined with lines, would represent the box expected (except there is a point in the middle, but when I use 26 as the count argument, then the point in the middle dissappears)

However when I use GL_POLYGON or GL_LINE_LOOP at the first argument to glDrawElements, I get rubbish. The 8 vertices are obviously there, but they’re joined up in really strange ways.

I’m pretty confused by now, and I’m not even sure I’m doing this correctly. Perhaps someone could put me in the right direction at least?

  • 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-28T18:46:00+00:00Added an answer on May 28, 2026 at 6:46 pm

    A rectangular prism is not a GL_POLYGON. Note the singular form of that word: polygon. As in one polygon. A rectangular prism is composed of many polygons, not just one.

    What you want is to draw some GL_TRIANGLES. Create an index list that shows each of the triangles that compose the box. That means each box face is made of two triangles, so you need 12 triangles total. That means 36 indices.

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm parsing an XML file, the creators of it stuck in a bunch social
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
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

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.