libGLV  0.4.0
Data Structures | Macros | Functions
glv.h File Reference

The GLV library provides a small, cross-platform interface for creating a window or fullscreen display with an OpenGL context. More...

#include <GL/glx.h>

Go to the source code of this file.

Data Structures

struct  GLViewEvent
 The GLViewEvent struct is passed to the event handler callback. More...
 
struct  GLView
 The GLView struct... More...
 
struct  GLViewMode
 The GLViewMode struct holds information about a video mode. More...
 

Macros

#define GLV_MODEID_WINDOW   -1
 

Functions

int glv_queryModes (GLViewMode_f func, void *)
 
GLViewglv_create (int attributes, int glVersion)
 
void glv_destroy (GLView *view)
 
int glv_attributes (GLView *view)
 
int glv_dpi (GLView *view)
 
int glv_changeMode (GLView *view, const GLViewMode *mode)
 
void glv_swapBuffers (GLView *view)
 
void glv_makeCurrent (GLView *view)
 
void glv_show (GLView *view)
 
void glv_hide (GLView *view)
 
void glv_setTitle (GLView *view, const char *title)
 
void glv_move (GLView *view, int x, int y)
 
void glv_resize (GLView *view, int w, int h)
 
void glv_raise (GLView *view)
 
void glv_iconify (GLView *view)
 
void glv_showCursor (GLView *view, int on)
 
void glv_setEventHandler (GLView *view, GLViewEvent_f func)
 
void glv_waitEvent (GLView *view)
 
void glv_handleEvents (GLView *view)
 
void glv_filterRepeatKeys (GLView *view, int on)
 
int glv_clipboardText (GLView *view, void(*func)(const char *data, int len, void *user), void *user)
 

Detailed Description

The GLV library provides a small, cross-platform interface for creating a window or fullscreen display with an OpenGL context.

Here is a short example of how to use GLV:

#include <glv.h>
#include <glv_keys.h>
void pickMode( const GLViewMode* mode, void* data )
{
// Pick the highest resolution available which is at least 16 bits deep.
GLViewMode* pick = (GLViewMode*) data;
if( (mode->width > pick->width) && (mode->depth >= 16) )
{
*pick = *mode;
}
}
void eventHandler( GLView* view, GLViewEvent* event )
{
if( event->type == GLV_EVENT_KEY_DOWN )
{
if( event->code == KEY_Escape )
{
int* quit = (int*) view->user;
*quit = 1;
}
}
}
int main()
{
int quit = 0;
GLView* view;
GLViewMode mode;
// Default to a window if no fullscreen modes are available.
mode.width = 640;
mode.height = 480;
glv_queryModes( pickMode, &mode );
view = glv_create( GLV_ATTRIB_DOUBLEBUFFER, 0 );
if( view )
{
view->user = &quit;
glv_setEventHandler( view, eventHandler );
glv_changeMode( view, &mode );
// Draw a blue screen using GL calls.
glClearColor( 0.1f, 0.2f, 1.0f, 0 );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glv_swapBuffers( view );
// Wait until the escape key is pressed.
while( ! quit )
{
glv_waitEvent( view );
}
glv_destroy( view );
}
return 0;
}

Macro Definition Documentation

◆ GLV_MODEID_WINDOW

#define GLV_MODEID_WINDOW   -1

A GLViewMode::id of GL_MODEID_WINDOW means the GLView is a window on the desktop rather than a fullscreen mode.

Function Documentation

◆ glv_attributes()

int glv_attributes ( GLView view)

Returns a mask of GL_ATTRIB_* bits which apply to the view.

◆ glv_changeMode()

int glv_changeMode ( GLView view,
const GLViewMode mode 
)

Returns non-zero if successful. It must not be called from within an input handler function.

To make a window for the view use the following code:

mode.width = 640;
mode.height = 480;
glv_changeMode( &view, &mode );
See also
glv_queryModes()

References GLV_MODEID_WINDOW, GLView::height, GLViewMode::height, GLViewMode::id, GLViewEvent::type, GLView::width, and GLViewMode::width.

◆ glv_clipboardText()

int glv_clipboardText ( GLView view,
void(*)(const char *data, int len, void *user)  func,
void *  user 
)

Calls func with the current system clipboard text.

Returns
Non-zero if data is present and func is called.

◆ glv_create()

GLView* glv_create ( int  attributes,
int  glVersion 
)

Creates a view. Returns a GLView pointer or zero if the view could not be created.

If glv_create fails then no other GLV function should be called (though it is safe to call glv_destroy()).

A valid view may be returned even if all attributes could not be set. Use glv_attributes() to check which are set.

Parameters
attributesThe possible attributes are GLV_ATTRIB_DOUBLEBUFFER, GLV_ATTRIB_STENCIL, GLV_ATTRIB_MULTISAMPLE, GLV_ATTRIB_ES, and GLV_ATTRIB_DEBUG. Only RGBA visuals will be created.
glVersionThis contains the OpenGL major version in bits 8-15 and the minor in bits 0-7, so version 3.2 is 0x302. If zero, no specific version is requested.

◆ glv_destroy()

void glv_destroy ( GLView view)

Closes the GLView and frees any used resources.

◆ glv_dpi()

int glv_dpi ( GLView view)

Returns vertical dots per inch of display.

◆ glv_filterRepeatKeys()

void glv_filterRepeatKeys ( GLView view,
int  on 
)

Enables or disables key repeat for the view. Repeat is on by default.

◆ glv_handleEvents()

void glv_handleEvents ( GLView view)

Calls the event handler for all pending events.

This should be called periodically (e.g. from your main loop).

// Example main loop.
running = 1;
while( running )
{
glv_handleEvents( &view );
// Update simulation...
// Draw frame using GL calls...
glv_swapBuffers( &view );
}
See also
glv_waitEvent()

References GLViewEvent::type.

◆ glv_hide()

void glv_hide ( GLView view)

Hides the window.

◆ glv_iconify()

void glv_iconify ( GLView view)

Minimizes the window.

◆ glv_makeCurrent()

void glv_makeCurrent ( GLView view)

Makes the GL context of the view current.

◆ glv_move()

void glv_move ( GLView view,
int  x,
int  y 
)

Positions window on screen. Should only be called when in windowed mode.

◆ glv_queryModes()

int glv_queryModes ( GLViewMode_f  func,
void *  data 
)

Calls func for each mode and returns the number of available fullscreen modes.

See also
glv_changeMode()

◆ glv_raise()

void glv_raise ( GLView view)

Show window on top of all other windows.

◆ glv_resize()

void glv_resize ( GLView view,
int  w,
int  h 
)

Sets window dimensions. Should only be called when in windowed mode.

◆ glv_setEventHandler()

void glv_setEventHandler ( GLView view,
GLViewEvent_f  func 
)

Sets the function called during glv_handleEvents()

◆ glv_setTitle()

void glv_setTitle ( GLView view,
const char *  title 
)

Sets window title and icon name.

◆ glv_show()

void glv_show ( GLView view)

Makes the window visible.

◆ glv_showCursor()

void glv_showCursor ( GLView view,
int  on 
)

Show or hide the native mouse pointer. There are no provisions to set the native pointer image. It is assumed that a GL primitive will be used for custom pointers.

◆ glv_swapBuffers()

void glv_swapBuffers ( GLView view)

Swaps the GL buffers of the view.

◆ glv_waitEvent()

void glv_waitEvent ( GLView view)

Waits until an event is recieved.

See also
glv_handleEvents()