This module provides integration with OpenGL and SDL functionality. More...
Go to the source code of this file.
Data Structures | |
struct | Camera |
struct | Texture |
Typedefs | |
typedef SDL_Surface *(* | PFN_IMG_LOAD )(const char *) |
Functions | |
void | mhCameraPosition (Camera *camera, int eye) |
Set the camera zoom, position and orientation. More... | |
PyObject * | Camera_convertToScreen (Camera *camera, PyObject *args) |
Convert 3D OpenGL world coordinates to screen coordinates. More... | |
PyObject * | Camera_convertToWorld2D (Camera *camera, PyObject *args) |
Convert 2D (x, y) screen coordinates to OpenGL world coordinates. More... | |
PyObject * | Camera_convertToWorld3D (Camera *camera, PyObject *args) |
Convert 3D (x, y, depth) screen coordinates to 3D OpenGL world coordinates. More... | |
static PyObject * | Camera_new (PyTypeObject *type, PyObject *args, PyObject *kwds) |
Takes care of the initialization of the Camera object members. More... | |
static int | Camera_init (Camera *self, PyObject *args, PyObject *kwds) |
The constructor of the Texture object. More... | |
void | RegisterCamera (PyObject *module) |
Registers the Camera object in the Python environment. More... | |
static PyObject * | Texture_loadImage (Texture *texture, PyObject *path) |
static void | Texture_dealloc (Texture *self) |
Takes care of the deallocation of the OpenGL texture. More... | |
static PyObject * | Texture_new (PyTypeObject *type, PyObject *args, PyObject *kwds) |
Takes care of the initialization of the Texture object members. More... | |
static int | Texture_init (Texture *self, PyObject *args, PyObject *kwds) |
The constructor of the Texture object. More... | |
void | RegisterTexture (PyObject *module) |
Registers the Texture object in the Python environment. More... | |
static uint32_t | swapLong (uint32_t inValue) |
Perform a byte swapping of a long value by reversing all bytes (e.g. 0x12345678 becomes 0x78563412). More... | |
static int | longCopyEndianSafe (uint32_t *destPtr, const uint32_t *srcPtr, size_t inLongs) |
Copy one Array of long values (32 bits) to another location in memory by considering the endian correctness. The rule here is that if the machine this method is a big endian architecture (e.g. PowerPC) then every long is swapped accordingly. On big endian architectures (as x86) no byte swapping will be done. More... | |
static void | mhFlipSurface (SDL_Surface *surface) |
Flip an SDL surface from top to bottom. More... | |
GLuint | mhLoadTexture (const char *fname, GLuint texture, int *width, int *height) |
Load a texture from a file and bind it into the textures array. More... | |
GLuint | mhCreateVertexShader (const char *source) |
GLuint | mhCreateFragmentShader (const char *source) |
GLuint | mhCreateShader (GLuint vertexShader, GLuint fragmentShader) |
int | mhGrabScreen (int x, int y, int width, int height, const char *filename) |
Capture a rectangular area from the screen into an image file. More... | |
void | mhKeyDown (int key, unsigned short character, int modifiers) |
Pass a keydown event up to Python. More... | |
void | mhKeyUp (int key, unsigned short character, int modifiers) |
unsigned int | mhTimerFunc (unsigned int interval, void *param) |
Pass a timer callback event up to Python. More... | |
void | mhMouseButtonDown (int b, int x, int y) |
Pass a mouse button down event up to Python. More... | |
void | mhMouseButtonUp (int b, int x, int y) |
Pass a mouse button up event up to Python. More... | |
void | mhMouseMotion (int s, int x, int y, int xrel, int yrel) |
Pass a mouse motion event up to Python and adjust current camera view. More... | |
void | UpdatePickingBuffer (void) |
void | mhGetPickedColor (int x, int y) |
Retrieve the 'selected' color index for the specified coordinates. More... | |
void | mhReshape (int w, int h) |
Redraw the contents of the window when the user resizes the window. More... | |
void | mhDrawBegin (void) |
Initialise the drawing space. More... | |
void | mhDrawEnd (void) |
Swap buffers following a redraw. More... | |
void | OnInit (void) |
Initialize lights and materials/textures. More... | |
void | OnExit (void) |
Delete materials/textures when the event loop exits. More... | |
void | mhDrawMeshes (int pickMode, int cameraType) |
Draw all of the 3D objects held in the G.world array matching the 'pickMode' setting. More... | |
void | mhDraw (void) |
Draw all visible 3D objects. More... | |
void | mhShutDown (void) |
Shutdown the MakeHuman Application. More... | |
void | mhQueueUpdate (void) |
Queue an update. More... | |
void | mhSetFullscreen (int fullscreen) |
Set fullscreen mode. More... | |
void | mhCreateWindow (int useTimer) |
Create SDL window. More... | |
void | mhEventLoop (void) |
Start the event loop to manage the MakeHuman GUI. More... | |
Variables | |
static int | g_savedx =0 |
static int | g_savedy =0 |
static int | g_desktopWidth = 0 |
static int | g_desktopHeight = 0 |
static int | g_windowWidth = 800 |
static int | g_windowHeight = 600 |
static SDL_Surface * | g_screen = NULL |
static void * | g_sdlImageHandle = NULL |
static PFN_IMG_LOAD | IMG_Load = NULL |
static PyMemberDef | Camera_members [] |
static PyMethodDef | Camera_methods [] |
PyTypeObject | CameraType |
static PyMemberDef | Texture_members [] |
static PyMethodDef | Texture_methods [] |
PyTypeObject | TextureType |
static unsigned char * | pickingBuffer = NULL |
static int | pickingBufferSize = 0 |
This module provides integration with OpenGL and SDL functionality.
Project Name: | MakeHuman |
Product Home Page: | http://www.makehuman.org/ |
SourceForge Home Page: | http://sourceforge.net/projects/makehuman/ |
Authors: | Manuel Bastioni, Paolo Colombo, Simone Re, Marc Flerackers, Hans-Peter Dusel |
Copyright(c): | MakeHuman Team 2001-2010 |
Licensing: | GPL3 (see also http://makehuman.wiki.sourceforge.net/Licensing) |
Coding Standards: | See http://makehuman.wiki.sourceforge.net/DG_Coding_Standards |
This module implements the OpenGL and SDL functions used to control the application window and to process user interaction with the GUI. It provides control functions to enable other application components to interact with the OpenGL and SDL functionality and invokes event handling functions to respond to keyboard and mouse events and idle time captured by the SDL (Simple DirectMedia Layer) libraries.
Definition in file glmodule.c.
typedef SDL_Surface*(* PFN_IMG_LOAD)(const char *) |
Definition at line 68 of file glmodule.c.
PyObject * Camera_convertToScreen | ( | Camera * | camera, |
PyObject * | args | ||
) |
Convert 3D OpenGL world coordinates to screen coordinates.
world | a list of doubles containing the 3D OpenGL world coordinates. |
screen | a list of doubles that will contain the screen coordinates. |
camera | an int indicating the camera mode (1=Scene or 0=GUI). |
This function converts 3D OpenGL world coordinates to screen coordinates based upon the specified camera setting.
Definition at line 1229 of file glmodule.c.
PyObject * Camera_convertToWorld2D | ( | Camera * | camera, |
PyObject * | args | ||
) |
Convert 2D (x, y) screen coordinates to OpenGL world coordinates.
screen | a list of doubles that will contain the screen coordinates. |
world | a list of doubles containing the 3D OpenGL world coordinates. |
camera | an int indicating the camera mode (1=Scene or 0=GUI). |
This function converts screen coordinates to 2D OpenGL world coordinates based upon the specified camera setting.
Definition at line 1259 of file glmodule.c.
PyObject * Camera_convertToWorld3D | ( | Camera * | camera, |
PyObject * | args | ||
) |
Convert 3D (x, y, depth) screen coordinates to 3D OpenGL world coordinates.
screen | a list of doubles that will contain the screen coordinates. |
world | a list of doubles containing the 3D OpenGL world coordinates. |
camera | an int indicating the camera mode (1=Scene or 0=GUI). |
This function converts screen coordinates to 3D OpenGL world coordinates based upon the specified camera setting.
Definition at line 1290 of file glmodule.c.
|
static |
The constructor of the Texture object.
self | The Texture object which is being constructed. |
args | The arguments. |
The constructor of the Texture object.
Definition at line 242 of file glmodule.c.
|
static |
Takes care of the initialization of the Camera object members.
self | The Camera object which is being initialized. |
This function takes care of the initialization of the Camera object members.
Definition at line 205 of file glmodule.c.
|
static |
Copy one Array of long values (32 bits) to another location in memory by considering the endian correctness. The rule here is that if the machine this method is a big endian architecture (e.g. PowerPC) then every long is swapped accordingly. On big endian architectures (as x86) no byte swapping will be done.
destPtr | the destination pointer (the target of the copy process). |
srcPtr | the source pointer which points to the data to copy from. |
inLongs | The count of long values to copy to. Note that this is not in bytes but in long values (1 long consumes 4 bytes) |
Definition at line 461 of file glmodule.c.
void mhCameraPosition | ( | Camera * | camera, |
int | eye | ||
) |
Set the camera zoom, position and orientation.
This function sets the camera zoom, position and orientation based upon the current settings found in global variables. This function is called before drawing the dynamic camera. If stereoMode is one of the two stereo modes, eye will determine which eye is drawn.
Definition at line 1424 of file glmodule.c.
GLuint mhCreateFragmentShader | ( | const char * | source | ) |
Definition at line 723 of file glmodule.c.
GLuint mhCreateShader | ( | GLuint | vertexShader, |
GLuint | fragmentShader | ||
) |
Definition at line 799 of file glmodule.c.
GLuint mhCreateVertexShader | ( | const char * | source | ) |
Definition at line 647 of file glmodule.c.
void mhCreateWindow | ( | int | useTimer | ) |
Create SDL window.
useTimer | an int controlling whether timer based processing is to be used (1=yes, 0=no). |
This function implements one of the first parts of the MakeHuman initiation sequence. It sets up the environment that the SDL module will use to manage the GUI window.
Definition at line 1920 of file glmodule.c.
void mhDraw | ( | void | ) |
Draw all visible 3D objects.
This function re-initializes the canvas and draws all of the 3D objects by making two calls to the mhDrawMeshes function. The first call draws all static objects (typically GUI controls). The second call draws all dynamic objects (e.g. the humanoid model)
Definition at line 1805 of file glmodule.c.
void mhDrawBegin | ( | void | ) |
Initialise the drawing space.
This function clears the screen and depth buffer and any previous transformations to initialize the drawing space.
Definition at line 1340 of file glmodule.c.
void mhDrawEnd | ( | void | ) |
Swap buffers following a redraw.
This function swaps the drawing buffers following a redraw.
Definition at line 1351 of file glmodule.c.
void mhDrawMeshes | ( | int | pickMode, |
int | cameraType | ||
) |
Draw all of the 3D objects held in the G.world array matching the 'pickMode' setting.
pickMode | an int indicating whether to use selection colors or draw colors. |
cameraType | an int specifying the camera type (movable or fixed). |
This function draws all of the 3D objects held in the G.world array, but it does it in two groups. It can be called to draw all of the fixed elements in the scene, such as the GUI controls or it can be called to draw all of the movable elements in the scenes (elements that can be moved, rotated etc.). Movable elements include the elements being modelled, such as the humanoid figure.
This function uses the glDrawElements function to add elements to the scene. It is used to provide an optimized interface for drawing the mesh. Note: Each vertex can only have a single UV value, which reduces the amount of data that needs to be transferred between Python and the C engine, but results in some artifacts along the UV seams.
Each model can be drawn in its natural color or in an adapted color to indicate that the model is currently selected. The pickMode parameter indicates which mode to use for this call.
Each object can be viewed using one or other of two different cameras:
Definition at line 1530 of file glmodule.c.
void mhEventLoop | ( | void | ) |
Start the event loop to manage the MakeHuman GUI.
This function implements the event loop which manages all user interaction, determining which functions to call to handle events etc.
Definition at line 2011 of file glmodule.c.
|
static |
Flip an SDL surface from top to bottom.
surface | a pointer to an SDL_Surface. |
This function takes an SDL surface, working line by line it takes the top line and swaps it with the bottom line, then the second line and swaps it with the second line from the bottom etc. until the surface has been mirrored from top to bottom.
Definition at line 482 of file glmodule.c.
void mhGetPickedColor | ( | int | x, |
int | y | ||
) |
Retrieve the 'selected' color index for the specified coordinates.
x | an int specifying the horizontal position in the image plane (in pixels). |
y | an int specifying the vertical position in the image plane (in pixels). |
This function draws a 'false' color image, assigning a unique sequencial color to each separate component using the current camera and scene settings. By retrieving the color index at the location in that image that corresponds to the mouse position during a mouse click the application can easily tell which object was selected. The resulting color index is assigned into the global variable 'G.color_picked'. This function always returns a '0'.
This function turns off lights and textures to draw only 'pure' colors, without shadows, reflections etc.
This technique is called Selection Using Unique Color IDs and uses glReadPixels() to read the single pixel under the current mouse location mapped to this invisible copy of the object.
For further information on this technique, see:
Definition at line 1199 of file glmodule.c.
int mhGrabScreen | ( | int | x, |
int | y, | ||
int | width, | ||
int | height, | ||
const char * | filename | ||
) |
Capture a rectangular area from the screen into an image file.
x | an int containing the x coordinate of the corner of the area (in pixels) |
y | an int containing the y coordinate of the corner of the area (in pixels) |
width | an int containing the width of the area in pixels |
height | an int containing the height of the area in pixels |
filename | a pointer to a char string containing the full path of the file on disk |
This function takes a rectangular section from the screen and writes an image to a bitmap image file on disk containing the pixels currently displayed in that section of screen.
Definition at line 888 of file glmodule.c.
void mhKeyDown | ( | int | key, |
unsigned short | character, | ||
int | modifiers | ||
) |
Pass a keydown event up to Python.
key | an int containing the key code of the key pressed. |
character | an unsigned short character containing the Unicode character corresponding to the key pressed. |
This function calls a keydown keyboard event handling function that will be bubbled up to the keyDown Python function and on to an appropriate handler function if registered against the Scene3D object. That function processes the event and control is returned to the event loop to await the next event.
Definition at line 948 of file glmodule.c.
void mhKeyUp | ( | int | key, |
unsigned short | character, | ||
int | modifiers | ||
) |
Definition at line 953 of file glmodule.c.
GLuint mhLoadTexture | ( | const char * | fname, |
GLuint | texture, | ||
int * | width, | ||
int * | height | ||
) |
Load a texture from a file and bind it into the textures array.
fname | a character string pointer to a string containing a file system path to a texture file. |
texture | an int specifying the existing texture id to use or 0 to create a new texture. |
This function loads a texture from a texture file and binds it into the OpenGL textures array.
Definition at line 520 of file glmodule.c.
void mhMouseButtonDown | ( | int | b, |
int | x, | ||
int | y | ||
) |
Pass a mouse button down event up to Python.
b | an int indicating which button this event relates to. |
x | an int specifying the horizontal mouse pointer position in the GUI window (in pixels). |
y | an int specifying the vertical mouse pointer position in the GUI window (in pixels). |
This function processes mouse clicks (mouse button down events). This function writes the current mouse position and keyboard modifier states (Shift, Ctl etc.) into globals. Then it calls one of a set of mouse click event handling functions that will be bubbled up to the corresponding Python event handler.
The Python Scene3D object holds separate attributes (sceneLMousePressedCallBack and sceneRMousePressedCallBack) to point to the different mouse button event handling functions.
Definition at line 1009 of file glmodule.c.
void mhMouseButtonUp | ( | int | b, |
int | x, | ||
int | y | ||
) |
Pass a mouse button up event up to Python.
b | an int indicating which button this event relates to. |
x | an int specifying the horizontal mouse pointer position in the GUI window (in pixels). |
y | an int specifying the vertical mouse pointer position in the GUI window (in pixels). |
This function processes mouse clicks (mouse button up events). This function writes the current mouse position and keyboard modifier states (Shift, Ctl etc.) into globals. Then it calls one of a set of mouse click event handling functions that will be bubbled up to the corresponding Python event handler.
The Python Scene3D object holds separate attributes (sceneLMouseReleasedCallBack and sceneRMouseReleasedCallBack) to point to the different mouse button event handling functions.
Definition at line 1052 of file glmodule.c.
void mhMouseMotion | ( | int | s, |
int | x, | ||
int | y, | ||
int | xrel, | ||
int | yrel | ||
) |
Pass a mouse motion event up to Python and adjust current camera view.
s | an int indicating the mouse.motion.state of the event (1=Mouse moved, 0=Mouse click). |
x | an int specifying the horizontal mouse pointer position in the GUI window (in pixels). |
y | an int specifying the vertical mouse pointer position in the GUI window (in pixels). |
xrel | an int specifying the difference between the previously recorded horizontal mouse pointer position in the GUI window and the current position (in pixels). |
yrel | an int specifying the difference between the previously recorded vertical mouse pointer position in the GUI window and the current position (in pixels). |
This function processes mouse movement events, calling a corresponding Python event handler.
This function writes the difference between the last recorded mouse position and the current mouse position, along with the current mouse position and keyboard modifier states (Shift, Ctl etc.) into globals. Then it calls a mouse click motion handling function that will be bubbled up to the Python function assigned to the sceneMouseMotionCallback attribute on the Scene3D object. That function processes the event and control is returned to the event loop to await the next event.
Definition at line 1096 of file glmodule.c.
void mhQueueUpdate | ( | void | ) |
Queue an update.
This function places an update event into the event queue if there isn't one pending already. This makes sure we don't create a "traffic jam" in the event queue when the system is slow in redrawing
Definition at line 1858 of file glmodule.c.
void mhReshape | ( | int | w, |
int | h | ||
) |
Redraw the contents of the window when the user resizes the window.
w | an int specifying the current width of the available canvas (in pixels). |
h | an int specifying the current height of the available canvas (in pixels). |
This function redraws the contents of the window when the user resizes it.
Definition at line 1316 of file glmodule.c.
void mhSetFullscreen | ( | int | fullscreen | ) |
Set fullscreen mode.
fullscreen | an int indicating whether to use a window or full screen mode. |
This function controls whether the MakeHuman GUI is displayed in a window or in full screen mode: 0 for windowed 1 for fullscreen
Definition at line 1881 of file glmodule.c.
void mhShutDown | ( | void | ) |
Shutdown the MakeHuman Application.
This function is part of the MakeHuman termination sequence prompted by a user electing to end the application.
This function sets loop to 0 which makes the event loop exit.
Definition at line 1847 of file glmodule.c.
unsigned int mhTimerFunc | ( | unsigned int | interval, |
void * | param | ||
) |
Pass a timer callback event up to Python.
interval | an unsigned int, not used here. |
param | a pointer, not used here. |
If the useTimer parameter is set when mhCreateWindow is called during the MakeHuman initiation sequence then this function is registered as the SDL timer event handler.
This function processes timer events. It creates a new event that it pushes into the event queue, it resets the timer and returns. This timer function is called in a separate thread, but the newly registered event is handled by the standard thread in mhEventLoop, where it calls callTimerFunct, which calls mainScene.timerFunc in the Python module.
Any Python functions registered to use this event perform their tasks before returning control to the event loop.
Definition at line 977 of file glmodule.c.
void OnExit | ( | void | ) |
Delete materials/textures when the event loop exits.
This function deletes materials/textures when the event loop is exited.
Definition at line 1407 of file glmodule.c.
void OnInit | ( | void | ) |
Initialize lights and materials/textures.
This function initializes lights and materials/textures available to a scene.
Definition at line 1360 of file glmodule.c.
void RegisterCamera | ( | PyObject * | module | ) |
Registers the Camera object in the Python environment.
module | The module to register the Camera object in. |
This function registers the Camera object in the Python environment.
Definition at line 191 of file glmodule.c.
void RegisterTexture | ( | PyObject * | module | ) |
Registers the Texture object in the Python environment.
module | The module to register the Texture object in. |
This function registers the Texture object in the Python environment.
Definition at line 333 of file glmodule.c.
|
static |
Perform a byte swapping of a long value by reversing all bytes (e.g. 0x12345678 becomes 0x78563412).
inValue | The long to swap to. |
Definition at line 429 of file glmodule.c.
|
static |
Takes care of the deallocation of the OpenGL texture.
self | The Texture object which is being deallocated. |
This function takes care of the deallocation of the OpenGL texture.
Definition at line 347 of file glmodule.c.
|
static |
The constructor of the Texture object.
self | The Texture object which is being constructed. |
args | The arguments. |
The constructor of the Texture object.
Definition at line 383 of file glmodule.c.
|
static |
Definition at line 396 of file glmodule.c.
|
static |
Takes care of the initialization of the Texture object members.
self | The Texture object which is being initialized. |
This function takes care of the initialization of the Texture object members.
Definition at line 361 of file glmodule.c.
void UpdatePickingBuffer | ( | void | ) |
Definition at line 1113 of file glmodule.c.
|
static |
Definition at line 100 of file glmodule.c.
|
static |
Definition at line 125 of file glmodule.c.
PyTypeObject CameraType |
Definition at line 143 of file glmodule.c.
|
static |
Definition at line 62 of file glmodule.c.
|
static |
Definition at line 61 of file glmodule.c.
|
static |
Definition at line 59 of file glmodule.c.
|
static |
Definition at line 60 of file glmodule.c.
|
static |
Definition at line 65 of file glmodule.c.
|
static |
Definition at line 69 of file glmodule.c.
|
static |
Definition at line 64 of file glmodule.c.
|
static |
Definition at line 63 of file glmodule.c.
|
static |
Definition at line 70 of file glmodule.c.
|
static |
Definition at line 1110 of file glmodule.c.
|
static |
Definition at line 1111 of file glmodule.c.
|
static |
Definition at line 261 of file glmodule.c.
|
static |
Definition at line 272 of file glmodule.c.
PyTypeObject TextureType |
Definition at line 285 of file glmodule.c.