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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:21:01+00:00 2026-05-10T17:21:01+00:00

This semester, I took a course in computer graphics at my University. At the

  • 0

This semester, I took a course in computer graphics at my University. At the moment, we’re starting to get into some of the more advanced stuff like heightmaps, averaging normals, tesselation etc.

I come from an object-oriented background, so I’m trying to put everything we do into reusable classes. I’ve had good success creating a camera class, since it depends mostly on the one call to gluLookAt(), which is pretty much independent of the rest of the OpenGL state machine.

However, I’m having some trouble with other aspects. Using objects to represent primitives hasn’t really been a success for me. This is because the actual render calls depend on so many external things, like the currently bound texture etc. If you suddenly want to change from a surface normal to a vertex normal for a particular class it causes a severe headache.

I’m starting to wonder whether OO principles are applicable in OpenGL coding. At the very least, I think that I should make my classes less granular.

What is the stack overflow community’s views on this? What are your best practices for OpenGL coding?

  • 1 1 Answer
  • 3 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. 2026-05-10T17:21:01+00:00Added an answer on May 10, 2026 at 5:21 pm

    The most practical approach seems to be to ignore most of OpenGL functionality that is not directly applicable (or is slow, or not hardware accelerated, or is a no longer a good match for the hardware).

    OOP or not, to render some scene those are various types and entities that you usually have:

    Geometry (meshes). Most often this is an array of vertices and array of indices (i.e. three indices per triangle, aka ‘triangle list’). A vertex can be in some arbitrary format (e.g. only a float3 position; a float3 position + float3 normal; a float3 position + float3 normal + float2 texcoord; and so on and so on). So to define a piece of geometry you need:

    • define it’s vertex format (could be a bitmask, an enum from a list of formats; …),
    • have array of vertices, with their components interleaved (‘interleaved arrays’)
    • have array of triangles.

    If you’re in OOP land, you could call this class a Mesh.

    Materials – things that define how some piece of geometry is rendered. In a simplest case, this could be a color of the object, for example. Or whether lighting should be applied. Or whether the object should be alpha-blended. Or a texture (or a list of textures) to use. Or a vertex/fragment shader to use. And so on, the possibilities are endless. Start by putting things that you need into materials. In OOP land that class could be called (surprise!) a Material.

    Scene – you have pieces of geometry, a collection of materials, time to define what is in the scene. In a simple case, each object in the scene could be defined by: – What geometry it uses (pointer to Mesh), – How it should be rendered (pointer to Material), – Where it is located. This could be a 4×4 transformation matrix, or a 4×3 transformation matrix, or a vector (position), quaternion (orientation) and another vector (scale). Let’s call this a Node in OOP land.

    Camera. Well, a camera is nothing more than ‘where it is placed’ (again, a 4×4 or 4×3 matrix, or a position and orientation), plus some projection parameters (field of view, aspect ratio, …).

    So basically that’s it! You have a scene which is a bunch of Nodes which reference Meshes and Materials, and you have a Camera that defines where a viewer is.

    Now, where to put actual OpenGL calls is a design question only. I’d say, don’t put OpenGL calls into Node or Mesh or Material classes. Instead, make something like OpenGLRenderer that can traverse the scene and issue all calls. Or, even better, make something that traverses the scene independent of OpenGL, and put lower level calls into OpenGL dependent class.

    So yes, all of the above is pretty much platform independent. Going this way, you’ll find that glRotate, glTranslate, gluLookAt and friends are quite useless. You have all the matrices already, just pass them to OpenGL. This is how most of real actual code in real games/applications work anyway.

    Of course the above can be complicated by more complex requirements. Particularly, Materials can be quite complex. Meshes usually need to support lots of different vertex formats (e.g. packed normals for efficiency). Scene Nodes might need to be organized in a hierarchy (this one can be easy – just add parent/children pointers to the node). Skinned meshes and animations in general add complexity. And so on.

    But the main idea is simple: there is Geometry, there are Materials, there are objects in the scene. Then some small piece of code is able to render them.

    In OpenGL case, setting up meshes would most likely create/activate/modify VBO objects. Before any node is rendered, matrices would need to be set. And setting up Material would touch most of remaining OpenGL state (blending, texturing, lighting, combiners, shaders, …).

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

Sidebar

Related Questions

I took a computer graphics course (graduate level) this past year. We spent the
I'm teaching a new course at a new University this semester, and I'm really
I took Computer Networking last semester and did some C programming in linux (using
In this coming semester, I am starting some research on large-scale distributed computing with
This semester, I will be a TA for an introductory computer science course at
I am starting a Qt course this semester. Having looked at the official documentation
I'm just finishing up a computer architecture course this semester where, among other things,
I am learning Computer Networking this semester, on which I find it quite interesting
This semester I'm teaching a class at a local university. Thus far, I've had
This semester in university I have a class called Data Structures, and the professor

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.