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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:27:59+00:00 2026-05-16T14:27:59+00:00

rookie C++ programmer here still. I’m using VC++ VS2008 compiler and glut library. All

  • 0

rookie C++ programmer here still.

I’m using VC++ VS2008 compiler and glut library. All working fine and up to date ( I know there’s 2010 just cba because of XNA (C#) support reasons)

Ok this time I have a question that is code related but I can make the code work. What I can not do is figure out what is happening under the hood. That’s what I’d like to figure out.

Assume all works, because clearly in runtime it works!

Here’s the code (minimized to what is actually running to it’s bare core to help speed this up)

#include "stdafx.h"
#include "Controller.h"
#include "glut.h"
#include <iostream>

void main(int argc, char** argv) 
{   
    glutInit(&argc, argv);
    //controller_ptr->InitController();  <---- no link to controller-->DrawScene

    //INIT GLUT
    //glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    //glutInitWindowSize(400, 400); //Set the window size
    //glutCreateWindow("Some Program"); 

    //INIT RENDERING
    glEnable(GL_DEPTH_TEST);

    glutDisplayFunc(drawScene);
    glutKeyboardFunc(handleKeypress);
    glutReshapeFunc(handleResize);
    glutMainLoop();
}

You may be thinking, hey you have the init code commented.
I do indeed. Guess what , it is still working! Why? I don’t really KNOW glut except on BBQ’s so ye…. <—- This could be a good point for you to call the fail if any

I have a drawscene class with this method

void DrawScene::initGlut()
{
    //Enables depth culling/front face culling??????  <----- what about that, some   depth thingy was involved is all I'm sure of
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(400, 400); //Set the window size
    glutCreateWindow("Some Program"); 
}

When I comment this and uncomment the one in the main, same result. I comment none, glut says init is done twice, I comment neither, init is not done it all goes boom. So the only logical conclusion would be to say this method is called, right?

There’s a bunch of other methods around and classes but there is no instance of the displayescene class nor controller class. I can comment the includes and it will do all the same.

Is there some design part I do not understand in MSbuild or VC++ development which allows methods to sift along some stream or flow that I am unaware of? As far as my knowledge goes, if I do not make an instance of a class it’s not relevant, at least it’s non-static members. So how can this code being active or inactive in this member have an effect on my program then?

Probably forgetting something incredibly stupid, but I’d rather find out a.s.a.p. anyway, the good part about being a rookie is that I couldn’t care less about falling flat on my face and trying again so fire away with the comments ^^

Thank you very much in advance!

EDIT: What the ? Now the console without any change to the code did report once a double call to init with the main init in comment and the one in drawscene not in comment…I am very much confused.

EDIT 2: 14:45 29/08/2010

Ok I found something….

The constructor in drawscene calls the initGlut and initRendering methods of the class. The controller makes a pointer to the heap holding a drawScene object there which causes the methods to run the init code.

The controller however is not included in the main nor is it instantiated. That drawScene code is run before the main starts and can I then conclude that the build itself is the problem so I should avoid init code in constructors?

EDIT 3: 15:02 29/08/2010

Found another , the double call does occur when only the drawScene is the active init code. Could it be that every include of drawscene causes constructor code to run init code and cause the double init?

  • 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-16T14:27:59+00:00Added an answer on May 16, 2026 at 2:27 pm

    Why not stick a break point on your init code and then walk up the call stack to see where it’s being called?

    Step through it slowly and I would imagine you’ll find the source..

    Edit: keeping initialisation of things like libraries out of the constructor is good practice. Personally, I would just test that glut has been initialised in the constructor if it’s required and throw an exception if it’s not detected.

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

Sidebar

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.