Additional information about developing models


Access to user interface and the animation timer.

There are several functions that are related to the user interface and the current animation time.  In order to access these functions from any method you have to to declare them external so that they are visible to the code that wants to call them.  The way to do this is to include LibModeler\modelerGUI.h.  This file provides the following statements:

extern lpScaleFunc scale;
extern lpCurveFunc curve;
extern lpCheckboxFunc checkbox;
extern lpMenuFunc menu;
extern lpGetTimeFunc get_time;

extern double get_control_d(int ctrl_id);
extern float get_control_f(int ctrl_id);
extern int get_control_i(int ctrl_id);
extern bool get_control_b(int ctrl_id);

 


Animation timer control

How do you reset the timer? and how do you allow to animate or not using code? (i.e. is there any way to call a function to animate/start the timer and stop it/reset it?)

The timer function is running through a 20 second loop. Depending on the rate selected, it increments the value every .2, .1, .05, etc and then it wraps at 20 seconds. Your redraw function is called every time the timer is updated while animating.

Although you can't easily change the values it generates, you could use it to drive a timer value of your own. You could increment your own static timer by whatever the get_time increment was and turn it off, reset it, or whatever you want depending on your own code and checkboxes or sliders in the UI.

 


Animation enabled?

What's the procedure to see if a particular menu item is checked? I can't  find where the constants are defined, I want to see if an animation is selected to be running or not.

You can't check directly on whether or not the user has selected animation mode. Redraw just gets called on a regular basis when you are animating.

One option is to just run continuously in animation mode, and have a checkbox or menu item in your UI to enable various sub-modes. For example, a menu could have the following choices: "use sliders for control", "enable timed animation mode 1", "enable timed animation mode 2". Your code then checks the menu and does the appropriate things.

 


OpenGL initialization

When you start to get fancy with OpenGL you sometimes want to do something of a "setup" nature that only happens once no matter how many times you redraw the image. (Creating textures from bitmap files is one example of this sort of thing.)

This sort of initialization does not happen in "init". Init is for setting up the User Interface widgets only. The OpenGL window and context do not exist when init is called and so you cannot do the setup there.

An easy solution is to put your initialization code into redraw in an "if" block that is controlled by a static variable. For example:

===============
void redraw(int drawmode) {
...
static bool initialized = false; // set to true the first time redraw is called
...
 if (!initialized) {
  initialized = true;
  printf("Vendor version %s %s\n",glGetString(GL_VENDOR),glGetString(GL_VERSION));
...
 }
...
}
===============

This initialization is only for things that happen once when you load the model originally. Actions that should happen every time you redraw should not be part of the if block.

 


OpenGL errors

It's a good idea to be checking errors as you go along. For example:

 GLenum error_flag;

 error_flag = glGetError();
 if (error_flag != GL_NO_ERROR) {
  printf("Error:  %1s (%i) in %1s.\n",gluErrorString(error_flag),error_flag,"redraw");
  }

 


Debugging

Under the debug tab in project settings you can set the name of the executable to run. The project skeletons came with that set to "..\Debug\modeler.exe".  You can set a breakpoint in your model code, then say go (F5 or the go button). The modeler will be started, you answer okay to continue (it's okay because you are not debugging the modeler), then you load your model as usual. When you execute the breakpoint in your code, you will bounce back to the debugger.

 


Clipping

Is there any easy way to make a section of a sphere?

See glClipPlane in the OGL references. Specify a clip plane, enable it, draw the sphere, disable the clip plane.