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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:50:35+00:00 2026-05-28T07:50:35+00:00

Background Information I’m currently taking a computer graphics class. The way we’re learning the

  • 0

Background Information

I’m currently taking a computer graphics class. The way we’re learning the main concepts is by making an abstraction that anyone could use (aka a simple 3D library). We’re using SDL for the real graphics part. Actually, all we use SDL for is to render and manipulate a pixel buffer. We’re only allowed to use that. But our abstraction is supposed to allow the client to draw pixels, lines, triangles, etc. all the way to complete models composed of those triangles.

Things were going along pretty smoothly… until the professor took a look at my abstraction. He said it wasn’t very object oriented.

My Question

I’m not looking so much for a review of my code, as I’m looking for some general advice and suggestions on how to design this SDL library using sound Object Oriented principles.

What I have so far

My code actually makes good use of some object oriented principles. I have the following objects working fine so far:

  • Vec4 – represents coordinates or colors. It does operations related to vectors.
  • Mat4 – represents a 4×4 matrix that I use for transformations and such. Does operations related to matrices, such as multiply by another matrix, by a vec4, etc.
  • MatrixFactory – creates different types of Mat4 (MatrixTranslate, MatrixRotate, etc)
  • Shape – an interface used to make drawing various shapes easier
    • Dot : Shape
    • Line : Shape
    • Triangle : Shape

My “engine” itself does the following (based somewhat on the three.js structure):

  • Creates a window (the main window where things are drawn)
  • Creates a scene (where shapes are displayed)
  • Registers callback functions based on keyboard events (key presses)

Where I’m struggling specifically

The main thing I’m struggling with so far is handling callbacks. For instance, to draw a triangle, I currently do something like the following:

int main()
{
    // Create instance of my library
    RDL* rdl = new RDL(WIDTH, HEIGHT, 32); 


    // Draw a triangle when T is pressed
    // RDL_KEY_t = #define RDL_KEY_t SDLK_t for consistency 
    rdl->registerKeyEvent(RDL_KEY_t, drawTriangle);

    rdl->show();

    return 0;
}


// X, Y, Z and R, G, B are random values not shown for simplicity
void drawTriangle(RDL* rdl)
{
    RDL_Point p1(Vec4(X, Y, Z), Vec4(R, G, B));
    RDL_Point p2(Vec4(X, Y, Z), Vec4(R, G, B));
    RDL_Point p3(Vec4(X, Y, Z), Vec4(R, G, B));

    rdl->insertShape(RDL_Triangle(pt1, pt2, pt3));
}

Inside RDL::show() I run the standard SDL loop where I do 2 things:

  • Call any registered callbacks
  • Drawn shapes in my vector where all shapes are stored

But this is no good. If I insert 10 triangles, they all draw nicely. But if I want to rotate a specific one, I can’t do that because my callbacks only give me access to my RDL object from main.

Any ideas, tips, or general advice?

Thank you very much. I know this is a long question…

  • 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-28T07:50:36+00:00Added an answer on May 28, 2026 at 7:50 am

    Your callbacks are plain old functions. This is what’s wrong with them. Imagine you can only have functions with no arguments. Or functions with one argument of a fixrmed type. You would not go too far with that. But your callbacks are just like that.

    You want to be able to pass a function and its arguments to your RegisterXyzEvent(). When the time comes, your framework should call the function with supplied arguments.

    A function bundled with (some of) its arguments is called in C++-speak a “bound function” or a “function object” or sometimes a “functor” (the last one is a very wrong name that unfortunately stuck). You need to learn how these bound functions work, how to build them, how to use ones that come with the standsrd library, and how to roll your own. Then make RegisterXyzEvent() accept such function objects, and make your framework call them.

    Some keywords to search: function object, boost::bind, std::function.

    Sorry about a brief answer with no examples. My phone keyboard is tiresome, and I think you are better off learning this stuff on your oelwn anyway.

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

Sidebar

Related Questions

Background information: I've searched stackoverflow for a specific solution and couldn't find one that
Background Information: I'm part of a team of developers that runs a web application
For a little background information, I've got an application that's running in a loop,
The Problem: Background Information I'm writing an application for a client that is to
Background information first: We are using a strongly-typed DataSet to manage transaction files. That
Background Information I have a distributed processing application that does data analysis. It is
Does MediaWiki provide a way to return the information present in 'Background Information' Table?
Some background information: I currently sell a niche software product for Windows PCs. Some
Background information: I presently have a hardware device that connects to the USB port.
Here is a little background information. I'm working on replacing a dll that 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.