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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:16:37+00:00 2026-05-13T17:16:37+00:00

I want to be able to store an atomic model in an OpenGL program

  • 0

I want to be able to store an atomic model in an OpenGL program I’m writing. Nothing fancy; just constant mesh vertex values stored as GLfloat[3], plus simple textures. I also want the model to be able to move and rotate freely and as a single object. Here’s what I have so far:

typedef struct _coordnode {
 GLfloat    *pts;           /* XYZ (vertex) or XY (texture) */
 struct _coordnode *next;
} coordnode;

typedef struct _facenode {
 GLfloat    *norm;          /* XYZ */
 coordnode  *vertices;      /* head of linked list */
 GLfloat    *color;         /* RGBA */
 coordnode  *textures;      /* head of linked list */
 struct _facenode *next;
} facenode;

typedef struct _model {
 GLenum     mode;
 facenode   *faces;         /* head of linked list */
 GLfloat    *rot;           /* delta-XYZ from Theta-origin */
 GLfloat    *rot_delta;     /* delta-delta-XYZ */
 GLfloat    *trans;         /* delta-XYZ from origin */
 GLfloat    *trans_delta;   /* delta-delta-XYZ from origin */
} model;

This sets itself up in such a way that the model has a linked lists of facenode, each of which has two linked lists of its vertexes and its texture coordinates, respectively.

Since this is my first C program, my question to seasoned programmers is whether this particular method presents any inconsistencies or inefficiencies, or whether it stores enough data.

More information, not necessarily relevant:

  • There will only be a few objects in memory, and a two of them will be involved in collision detection.
  • One model will have a partial transparency.
  • One model will have raised rendered text applied to the model’s faces, and move according to a gravity vector.
  • Two models will rotate as one, based on external input.
  • 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-13T17:16:37+00:00Added an answer on May 13, 2026 at 5:16 pm

    Assuming that you are on a 32 bit architecture, and GLgloat is typedef’d to a 32 bit float this structure

    typedef struct _coordnode {
     GLfloat   *pts;            /* XYZ (vertex) or XY (texture) */
     struct _coordnode *next;
    } coordnode;
    

    is going to consume 8 bytes of memory. Then, if I understand this correctly, pts will point to a separate allocation that will have either 2 or 3 GlFloats, which is 8 or 12 bytes of memory. that’s 16 or 20 bytes in two allocations. while this

    typedef struct _coordnode {
     GLfloat   pts[3];           /* XYZ (vertex) or XY (texture) */
     struct _coordnode *next;
    } coordnode;
    

    Is always 16 bytes, plus one less point of failure since it’s a single allocation rather than two.

    So, even if your allocator has zero overhead (and it doesn’t). Putting 3 GLfloats in the coordnode (even if you only use 2 of them) is less memory than having the GLfloat array be a separate allocaton. Plus, if you make this a single allocation then you get better cache coherency, which translates into better performance most of the time.

    The same analysis can be performed on your other structures.

    The other thing I would say is that if you always put the next pointer first in each of your structures, then a single set of linked list functions can handle all of your lists, so IMO this is better

    typedef struct _coordnode {
     struct _coordnode *next;
     GLfloat   pts[3];           /* XYZ (vertex) or XY (texture) */
    } coordnode;
    

    If you someday change to doubles for GLFloat or move to a 64 bit architecture, then your pointers will no longer be the same size as your GLFloats. In that case, it would be better use of memory to group the floats and pointers together.

    typedef struct _facenode {
     struct _facenode *next;
     coordnode  *vertices;      /* head of linked list */
     coordnode  *textures;      /* head of linked list */
     GLfloat   *norm;           // XYZ (it might be better to make this an array)
     GLfloat   *color;          // RGBA (it might be better to make this an array)
    } facenode;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 325k
  • Answers 325k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Yes - you can ;-) Just define all three foreign… May 14, 2026 at 1:26 am
  • Editorial Team
    Editorial Team added an answer jQuery doesn't have a method for JSON stringifying native objects.… May 14, 2026 at 1:26 am
  • Editorial Team
    Editorial Team added an answer If the request dictionary is really so limited, the only… May 14, 2026 at 1:26 am

Related Questions

I want to be able to store a decimal value in one column, and
I want to store an array in a record. Table1: ID, Name, Friends (friends
I am having some issues with word-splitting in bash variable expansion. I want to
I have a swing client that renders HTML through the use of the JEditorPane
I want to be able to store a backgroundcolor for a panel in my

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.