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

The Archive Base Latest Questions

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

GLUT is a great API and it’s very easy to use but I am

  • 0

GLUT is a great API and it’s very easy to use but I am having some difficulty with how it handles scope. When defining callbacks there is no option to pass parameters so it seems to me as though the programmer is forced to rely on global variables, which I find difficult to accept. Right now I have all the GLUT code in it’s own module, running on it’s own thread, and define a static pointer which I assign at the entry point to the module, like so:

Main module

int main( int argc, char** argv ) {
    int foo;
    boost::thread graphicsThread(glutMain, argc, argv, &foo);

    //...

    graphicsThread.join();
    return 0;
}

GLUT module

static int* FOO_REF;

int glutMain( int argc, char** argv, int* foo ) {
    FOO_REF = foo;
    glutInit(&argc, argv);
    //etc...

Is there a better solution than this?

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

    If you’re using freeglut or a derivative and willing to confine yourself to freeglut derivatives only it has a non-standard extension to solve exactly the problem. You can associate a void* with every window. If you make that a struct that contains all the per-window data you want you can avoid the globals entirely.

    Synopsis:

    #include <GL/glut.h>
    #include <GL/freeglut_ext.h>
    
    
    void * glutGetWindowData();
    glutSetWindowData(void *data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm not very good with C but I'm designing a GLUT application that
I am using OpenGL/GLUT to implement Bresenham's line drawing algorithm and having some issues
I've been using GLUT for menu'es in openGl programs for some time now, but
I use GLUT to create window ( glutCreateWindow() ). It seems like glut creates
I know I can do it with GLUT. But, I have a big project
I am trying to write a GLUT application in C++ that requires some simple
I have a standard glut implementation. The display function redraws each object, but I
I am using GLUT for my windowing system to output some images onto the
Im having an issue using GLUT with monodevelop. Im using the following code: #include
I'm trying to use GLUT (freeglut) in my OpenGL application, and I need to

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.