Aros/Developer/OpenGL

From Wikibooks, open books for an open world
Jump to: navigation, search
Navbar for the Aros wikibook
Aros User Docs
Aros User Docs
Aros User FAQs
Aros User Applications
Aros User DOS Shell
Aros/User/AmigaLegacy
Aros Dev Docs
Aros Developer Docs
Porting Software from AmigaOS/SDL
For Zune Beginners
Zune .MUI Classes
For SDL Beginners
Aros Developer BuildSystem
Specific platforms
68k Support
PPC Power Architecture Support
Arm Raspberry Pi Support
Android support
Linux and FreeBSD Support
Windows Mingw and MacOSX Support
Aros x86 Installing
Aros x86 Audio/Video Support
Aros x86 Network Support
Aros x86 Complete System HCL
Aros Storage Support IDE SATA etc
Aros Poseidon USB Support
x86-64 Support
misc
Aros Public License


Introduction[edit]

The Amiga's first introduction to hardware enhanced 3D was Warp3D. This was followed by an open source(software based) equivalent called Wazp3D A Wazp3D adaptation to AROS from Matthias Rustler appeared on December 2007. During 2009 Krzysztof "Deadwood" Smiechowicz ported version 7.5 of MESA 3D to AROS. MESA 3D provides a generic OpenGL implementation. Then he added hardware 3D acceleration capabilities to AROS with his port of Gallium3D for MESA 3D. Then on September 2011 Wazp3D was linked to Mesa 3D for hardware enhanced 3D.



Compiling[edit]

WARP3D[edit]

Recompiling a program that use Warp3D.library is quite simple. You just need to link it to Warp3D

So compiling cow3d for Aros x86 was as simple as gcc -c -O3 CoW3D-3.c -o Cow3D-Aros -lWarp3D

Wazp3D-Prefs is a little tool for selecting how Wazp3D works (fast or nice).

Aros version is included with Aminet/Cow3D (see Wazp3D homepage for documentation) Option "Renderer:Soft to Image" is safer if your Aros system dont support LockBitmapTags() else "Renderer:Soft to Bitmap" If your Aros support "Native Graphics Aros" then you can try "Renderer:hard overlay" or "Renderer:hard" but the display is not perfect as Mesa dont support rendering to bitmap as Warp3D


You need to use W3D_DrawTriFan(), W3D_DrawTriSttrip() or better still, W3D_DrawArray() with their corresponding data structures. Suggest the latter since you have much more control over how the vertex data is organised.

You create a triangle strip or a triangle fan. In a strip, alternate triangles share two points along an edge. In a fan, all triangles share one common vertex and adjacent triangles also share an edge. The simplest to illustrate is the strip. A rectangle is simply a 2 triangle strip, something like this:

V[0]--V[1]
|      /|
|     / |
|    /  |
|   /   |
|  /    |
V[2]--V[3]

Using one of the strip drawing methods, the same texture is applied to all polygons in the strip. If you use the old single triangle routines, you have to either enable global texture environment or specify the texture in each polygon separately.

Warp3D is a rasterizer only. That means that it draws primitives in screen space. Stictly, the axes are defined as X=left to right in pixels, Y top to botton in pixels, Z is plane of the screen into the distance. The valid range for Z is 0.0 - 1.0.

You need to calculate your vertices in screen space directly or write your own transformation pipeline.

See Starship3D


MESA 3D[edit]

From client perspective using mesa.library is quite simple:

1) For programs that simply use OpenGL and Glut (like Aminet/starship) then just compile them

gcc starship.c -lglut -lgl - o starshiparos


2) For programs that use OpenGL and Amiga windowing system

  • Create a window
  • Call AROSMesaCreateContext passing it the window and some other stuff -> you get rendering context in return
  • Call AROSMesaMakeCurrent passing it the context so that AROSMesa knows what to render on
  • Render some stuff using glXXX functions
  • Call AROSMesaSwapBuffers to have the content of render buffer painted onto your window
  • Loop to glXXX functions

[...]

  • Call AROSMesaDestroyContext(context);
  • Call CloseWindow(window);


OpenGL API has been changed in ABI V1, just rename 'glA' to 'AROSMesa' The VBO functions are still there, but you need to access them via glaGetProcAddress.


#include <exec/types.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <intuition/screens.h>
#include <cybergraphx/cybergraphics.h>
 
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/intuition.h>
 
#include <proto/timer.h>
#include <devices/timer.h>
#include <proto/cybergraphics.h>
 
#define GL_GLEXT_PROTOTYPES
#include <GL/arosmesa.h>
 
#include <stdio.h>
 
AROSMesaContext     glcont=NULL;
double              angle = 0.0;
double              angle_inc = 0.0;
BOOL                finished = FALSE;
struct Window *     win = NULL;
struct Device *     TimerBase = NULL;
struct timerequest  timereq;
struct MsgPort      timeport;
struct Library *    CyberGfxBase = NULL;
BOOL                fullscreen = FALSE;
 
GLuint              fragmentShader = 0;
GLuint              vertexShader = 0;
GLuint              shaderProgram = 0;
GLint               angleLocation = 0;
 
 
const GLchar * fragmentShaderSource =
"uniform float angle;"
"void main()"
"{"
"   vec4 v = vec4(gl_Color);"
"   float intensity = abs(1.0f - (mod(angle, 1440.0f) / 720.0f));"
"   v.b = v.b * intensity;"
"   v.g = v.g * (1.0f - intensity);"
"	gl_FragColor = v;"
"}";
 
const GLchar * vertexShaderSource =
"void main()"
"{	"
"   gl_FrontColor = gl_Color;"
"	gl_Position = ftransform();"
"}";
 
 
#define RAND_COL 1.0f
#define DEGREES_PER_SECOND 180.0
#define USE_PERSPECTIVE 1
 
void prepare_shader_program()
{
#define BUFFER_LEN 2048
    char buffer[BUFFER_LEN] = {0};
    int len;
 
    fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL);
    glCompileShader(fragmentShader);
    glGetShaderInfoLog(fragmentShader, BUFFER_LEN, &len, buffer);
    printf("Fragment shader compile output: %s\n", buffer);
 
    vertexShader = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(vertexShader, 1, &vertexShaderSource, NULL);
    glCompileShader(vertexShader);
    glGetShaderInfoLog(vertexShader, BUFFER_LEN, &len, buffer);
    printf("Vertex shader compile output: %s\n", buffer);
 
    shaderProgram = glCreateProgram();
    glAttachShader(shaderProgram, vertexShader);
    glAttachShader(shaderProgram, fragmentShader);
    glLinkProgram(shaderProgram); 
    glGetProgramInfoLog(shaderProgram, BUFFER_LEN, &len, buffer);
    printf("Shader program compile output: %s\n", buffer);
 
#undef BUFFER_LEN    
}
 
void cleanup_shader_program()
{
    glUseProgram(0);
    glDetachShader(shaderProgram, fragmentShader);
    glDetachShader(shaderProgram, vertexShader);
    glDeleteShader(fragmentShader);
    glDeleteShader(vertexShader);
    glDeleteProgram(shaderProgram);
}
 
void render_face()
{
    glBegin(GL_QUADS);
        glColor4f(RAND_COL , 0.0, RAND_COL, 0.3);
        glVertex3f(-0.25, -0.25, 0.0);
        glColor4f(0, RAND_COL, RAND_COL, 0.3);
        glVertex3f(-0.25, 0.25, 0.0);
        glColor4f(0 , 0, 0, 0.3);
        glVertex3f(0.25, 0.25, 0.0);
        glColor4f(RAND_COL , RAND_COL, 0, 0.3);
        glVertex3f(0.25, -0.25, 0.0);
    glEnd();
 
}
 
void render_cube()
{
    glPushMatrix();
    glRotatef(0.0, 0.0, 1.0, 0.0);
    glTranslatef(0.0, 0.0, 0.25);
    render_face();
    glPopMatrix();
 
 
    glPushMatrix();
    glRotatef(90.0, 0.0, 1.0, 0.0);
    glTranslatef(0.0, 0.0, 0.25);
    render_face();
    glPopMatrix();
 
    glPushMatrix();
    glRotatef(180.0, 0.0, 1.0, 0.0);
    glTranslatef(0.0, 0.0, 0.25);
    render_face();
    glPopMatrix();
 
    glPushMatrix();
    glRotatef(270.0, 0.0, 1.0, 0.0);
    glTranslatef(0.0, 0.0, 0.25);
    render_face();
    glPopMatrix();
 
    glPushMatrix();
    glRotatef(90.0, 1.0, 0.0, 0.0);
    glTranslatef(0.0, 0.0, 0.25);
    render_face();
    glPopMatrix();
 
    glPushMatrix();
    glRotatef(-90.0, 1.0, 0.0, 0.0);
    glTranslatef(0.0, 0.0, 0.25);
    render_face();
    glPopMatrix();
}
 
void render_triangle()
{
    glBegin(GL_TRIANGLES);
        glColor4f(1.0, 0.0, 0.0, 1.0);
        glVertex3f(-0.25, -0.25, 0.0);
        glColor4f(0.0, 1.0, 0.0, 1.0);
        glVertex3f(-0.25,  0.25, 0.0);
        glColor4f(0.0, 0.0, 1.0, 1.0);
        glVertex3f( 0.25,  0.25, 0.0);
    glEnd();
}
 
void render()
{
    glLoadIdentity();
    glClearColor(0.3, 0.3, 0.3, 1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glCullFace(GL_BACK);
    glDepthFunc(GL_LESS);
    glEnable(GL_DEPTH_TEST);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
    glEnable(GL_BLEND);
 
    angle += angle_inc;
    glUniform1f(angleLocation, angle);
 
#if USE_PERSPECTIVE == 1
    glTranslatef(0.0, 0.0, -6.0);
#endif    
    glPushMatrix();
    glRotatef(angle, 0.0, 1.0, 0.0);
    glTranslatef(0.0, 0.0, 0.25);
    glRotatef(angle, 1.0, 0.0, 1.0);
    render_cube();
    glPopMatrix();
 
    glDisable(GL_BLEND);
    glDisable(GL_DEPTH_TEST);
 
    AROSMesaSwapBuffers(glcont);
}    
 
#define VISIBLE_WIDTH 300
#define VISIBLE_HEIGHT 300
 
void initmesa()
{
    struct TagItem attributes [ 14 ]; /* 14 should be more than enough :) */
    int i = 0;
    GLfloat h = 0.0f;
 
    attributes[i].ti_Tag = AMA_Window;      attributes[i++].ti_Data = (IPTR)win;
    attributes[i].ti_Tag = AMA_Left;        attributes[i++].ti_Data = win->BorderLeft;
    attributes[i].ti_Tag = AMA_Top;         attributes[i++].ti_Data = win->BorderTop;
    attributes[i].ti_Tag = AMA_Bottom;      attributes[i++].ti_Data = win->BorderBottom;
    attributes[i].ti_Tag = AMA_Right;       attributes[i++].ti_Data = win->BorderRight;
 
    // double buffer ?
    attributes[i].ti_Tag = AMA_DoubleBuf;   attributes[i++].ti_Data = GL_TRUE;
 
    // RGB(A) Mode ?
    attributes[i].ti_Tag = AMA_RGBMode;     attributes[i++].ti_Data = GL_TRUE;
 
    /* Stencil/Accum */
    attributes[i].ti_Tag = AMA_NoStencil;   attributes[i++].ti_Data = GL_TRUE;
    attributes[i].ti_Tag = AMA_NoAccum;     attributes[i++].ti_Data = GL_TRUE;
 
    // done...
    attributes[i].ti_Tag    = TAG_DONE;
 
    glcont = AROSMesaCreateContext(attributes);
    if (glcont)
    {
        AROSMesaMakeCurrent(glcont);
        h = (GLfloat)VISIBLE_HEIGHT / (GLfloat)VISIBLE_WIDTH ;
 
        glViewport(0, 0, (GLint) VISIBLE_WIDTH, (GLint) VISIBLE_HEIGHT);
#if USE_PERSPECTIVE == 1
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glFrustum(-1.0, 1.0, -h, h, 5.0, 200.0);
        glMatrixMode(GL_MODELVIEW);
#endif
        prepare_shader_program();
        glUseProgram(shaderProgram);
        angleLocation = glGetUniformLocation(shaderProgram, "angle");
    }
    else
        finished = TRUE; /* Failure. Stop */
}
 
void deinitmesa()
{
    if (glcont) 
    {
        cleanup_shader_program();
        AROSMesaDestroyContext(glcont);
    }
}
 
static int init_timerbase()
{
    timeport.mp_Node.ln_Type   = NT_MSGPORT;
    timeport.mp_Node.ln_Pri    = 0;
    timeport.mp_Node.ln_Name   = NULL;
    timeport.mp_Flags          = PA_IGNORE;
    timeport.mp_SigTask        = FindTask(NULL);
    timeport.mp_SigBit         = 0;
    NEWLIST(&timeport.mp_MsgList);
 
    timereq.tr_node.io_Message.mn_Node.ln_Type    = NT_MESSAGE;
    timereq.tr_node.io_Message.mn_Node.ln_Pri     = 0;
    timereq.tr_node.io_Message.mn_Node.ln_Name    = NULL;
    timereq.tr_node.io_Message.mn_ReplyPort       = &timeport;
    timereq.tr_node.io_Message.mn_Length          = sizeof (timereq);
 
    if(OpenDevice("timer.device",UNIT_VBLANK,(struct IORequest *)&timereq,0) == 0)
    {
        TimerBase = (struct Device *)timereq.tr_node.io_Device;
        return 1;
    }
    else
    {
        return 0;
    }
}
 
 
static void deinit_timerbase()
{
    if (TimerBase != NULL)
        CloseDevice((struct IORequest *)&timereq);
}
 
 
void HandleIntuiMessages(void)
{
    struct IntuiMessage *msg;
 
    while((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
    {
        switch(msg->Class)
        {
        case IDCMP_CLOSEWINDOW:
            finished = TRUE;
            break;
        case IDCMP_VANILLAKEY:
            if (msg->Code == 27 /* ESC */) finished = TRUE;
            break;
        }
        ReplyMsg((struct Message *)msg);
    }
}
 
 
#define ARG_FULLSCREEN  0
#define NUM_ARGS        1
 
STATIC CONST_STRPTR   TEMPLATE=(CONST_STRPTR) "FULLSCREEN/S";
static struct RDArgs  *myargs;
static IPTR           args[NUM_ARGS];
 
void get_arguments(void)
{
    if((myargs = ReadArgs(TEMPLATE, args, NULL)))
    {
        fullscreen = (BOOL)args[ARG_FULLSCREEN];
        FreeArgs(myargs);
    }
}
 
/*
** Open a simple window using OpenWindowTagList()
*/
int main(void)
{
    ULONG fps = 0;
//    ULONG exitcounter = 0;
    TEXT title[100];
    struct Screen * pubscreen = NULL;
    struct Screen * customscreen = NULL;
    LONG modeid;
 
    struct timeval tv;
    UQUAD lastmicrosecs = 0L;
    UQUAD currmicrosecs = 0L;
    UQUAD fpsmicrosecs = 0L;
 
    get_arguments();
 
    init_timerbase();
 
    GetSysTime(&tv);
    lastmicrosecs = tv.tv_secs * 1000000 + tv.tv_micro;
    fpsmicrosecs = lastmicrosecs;
 
    if (fullscreen)
    {
        CyberGfxBase = OpenLibrary("cybergraphics.library", 0L);
 
        modeid = BestCModeIDTags(CYBRBIDTG_NominalWidth, VISIBLE_WIDTH,
                                    CYBRBIDTG_NominalHeight, VISIBLE_HEIGHT,
                                    TAG_DONE);
 
        customscreen = OpenScreenTags(NULL,
                            SA_Type,        CUSTOMSCREEN,
                            SA_DisplayID,   modeid,
                            SA_Width,       VISIBLE_WIDTH,
                            SA_Height,      VISIBLE_HEIGHT,
                            SA_ShowTitle,   FALSE,
                            SA_Quiet,       TRUE,
                            TAG_DONE);
 
        win = OpenWindowTags(NULL,
                WA_Left,            0,
                WA_Top,             200,
                WA_InnerWidth,      VISIBLE_WIDTH,
                WA_InnerHeight,     VISIBLE_HEIGHT,
                WA_CustomScreen,    (IPTR)customscreen,
                WA_Flags,           WFLG_ACTIVATE | WFLG_BACKDROP | WFLG_BORDERLESS | WFLG_RMBTRAP,
                WA_IDCMP,           IDCMP_VANILLAKEY,
                TAG_DONE);
    }
    else
    {
        if ((pubscreen = LockPubScreen(NULL)) == NULL) return 1;
 
        win = OpenWindowTags(0,
                            WA_Title, (IPTR)"MesaSimpleRendering",
                            WA_PubScreen, pubscreen,
                            WA_CloseGadget, TRUE,
                            WA_DragBar, TRUE,
                            WA_DepthGadget, TRUE,
                            WA_Left, 50,
                            WA_Top, 200,
                            WA_InnerWidth, VISIBLE_WIDTH,
                            WA_InnerHeight, VISIBLE_HEIGHT,
                            WA_Activate, TRUE,
                            WA_RMBTrap, TRUE,
                            WA_SimpleRefresh, TRUE,
                            WA_NoCareRefresh, TRUE,
                            WA_IDCMP, IDCMP_VANILLAKEY | IDCMP_CLOSEWINDOW,
                            TAG_DONE);
 
        UnlockPubScreen(NULL, pubscreen);
    }
 
    initmesa();
//    finished = TRUE;
    while(!finished)
    {
        GetSysTime(&tv);
        currmicrosecs = tv.tv_secs * 1000000 + tv.tv_micro;
 
        if (currmicrosecs - fpsmicrosecs > 1000000)
        {
            /* FPS counting is naive! */
            fpsmicrosecs += 1000000;
            sprintf(title, "MesaSimpleRendering, FPS: %d", fps);
            SetWindowTitles(win, title, (UBYTE *)~0L);
            fps = 0;
        }
 
        angle_inc = ((double)(currmicrosecs - lastmicrosecs) / 1000000.0) * DEGREES_PER_SECOND;
        lastmicrosecs = currmicrosecs;
 
        fps++; 
        render();
        HandleIntuiMessages();
//        exitcounter++;
//        Delay(10);
//        if (exitcounter > 0) finished = TRUE;
    }
 
    deinitmesa();
 
    deinit_timerbase();
 
    CloseWindow(win);
 
    if (customscreen) CloseScreen(customscreen);
 
    if (CyberGfxBase) CloseLibrary(CyberGfxBase);
 
    return 0;
}



/*
Copyright (C) 2006-2011 Mark Olsen
 
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 
See the GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
 
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <intuition/extensions.h>
#include <cybergraphx/cybergraphics.h>
 
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/cybergraphics.h>
 
#include <GL/arosmesa.h>
 
#include "quakedef.h"
#include "input.h"
#include "keys.h"
#include "gl_local.h"
#include "in_morphos.h"
#include "vid_mode_morphos.h"
 
struct Library *MesaBase = 0;
 
struct display
{
	void *inputdata;
 
	unsigned int width, height;
	int fullscreen;
	char used_mode[256];
 
	struct Screen *screen;
	struct Window *window;
 
	void *pointermem;
 
	char pal[256*4];
 
	AROSMesaContext mesacontext;
};
 
void Sys_Video_CvarInit(void)
{
}
 
void *Sys_Video_Open(const char *mode, unsigned int width, unsigned int height, int fullscreen, unsigned char *palette)
{
	struct display *d;
	struct modeinfo modeinfo;
	char monitorname[128];
	int r;
	int i;
 
	d = AllocVec(sizeof(*d), MEMF_CLEAR);
	if (d)
	{
		MesaBase = OpenLibrary("mesa.library", 0);
		if (MesaBase)
		{
			if (fullscreen)
			{
				if (*mode && modeline_to_modeinfo(mode, &modeinfo))
				{
					snprintf(monitorname, sizeof(monitorname), "%s.monitor", modeinfo.monitorname);
					d->screen = OpenScreenTags(0,
						SA_Width, modeinfo.width,
						SA_Height, modeinfo.height,
						SA_Depth, modeinfo.depth,
#if 0
						SA_MonitorName, monitorname,
#endif
						SA_Quiet, TRUE,
						TAG_DONE);
				}
				else
				{
					d->screen = OpenScreenTags(0,
						SA_Quiet, TRUE,
						TAG_DONE);
				}
 
				if (d->screen)
				{
					width = d->screen->Width;
					height = d->screen->Height;
 
					snprintf(d->used_mode, sizeof(d->used_mode), "Dunno,%d,%d,42", width, height);
				}
				else
					fullscreen = 0;
			}
 
			if (d->screen || !fullscreen)
			{
				d->window = OpenWindowTags(0,
					d->screen?WA_Width:WA_InnerWidth, width,
					d->screen?WA_Height:WA_InnerHeight, height,
					WA_Title, "FodQuake",
					WA_DragBar, d->screen?FALSE:TRUE,
					WA_DepthGadget, d->screen?FALSE:TRUE,
					WA_Borderless, d->screen?TRUE:FALSE,
					WA_RMBTrap, TRUE,
					d->screen?WA_CustomScreen:TAG_IGNORE, (IPTR)d->screen,
					WA_Activate, TRUE,
					TAG_DONE);
 
				if (d->window)
				{
					d->mesacontext = AROSMesaCreateContextTags(
						AMA_Window, d->window,
						AMA_Left, d->screen?0:d->window->BorderLeft,
						AMA_Top, d->screen?0:d->window->BorderTop,
						AMA_Width, width,
						AMA_Height, height,
						AMA_NoStencil, TRUE,
						AMA_NoAccum, TRUE,
						TAG_DONE);
 
					if (d->mesacontext)
					{
						AROSMesaMakeCurrent(d->mesacontext);
 
						d->pointermem = AllocVec(256, MEMF_ANY|MEMF_CLEAR);
						if (d->pointermem)
						{
							SetPointer(d->window, d->pointermem, 16, 16, 0, 0);
 
							d->width = width;
							d->height = height;
							d->fullscreen = fullscreen;
 
							d->inputdata = Sys_Input_Init(d->screen, d->window);
							if (d->inputdata)
							{
								return d;
							}
 
							FreeVec(d->pointermem);
						}
 
						AROSMesaMakeCurrent(0);
						AROSMesaDestroyContext(d->mesacontext);
					}
 
					CloseWindow(d->window);
				}
 
				if (d->screen)
					CloseScreen(d->screen);
			}
 
			CloseLibrary(MesaBase);
		}
 
		FreeVec(d);
	}
 
	return 0;
}
 
void Sys_Video_Close(void *display)
{
	struct display *d = display;
 
	Sys_Input_Shutdown(d->inputdata);
 
	AROSMesaMakeCurrent(0);
	AROSMesaDestroyContext(d->mesacontext);
 
	CloseWindow(d->window);
 
	FreeVec(d->pointermem);
 
	if (d->screen)
		CloseScreen(d->screen);
 
	CloseLibrary(MesaBase);
 
	FreeVec(d);
}
 
unsigned int Sys_Video_GetNumBuffers(void *display)
{
	struct display *d;
 
	d = display;
 
	return d->screen ? 3 : 1;
}
 
int Sys_Video_GetKeyEvent(void *display, keynum_t *keynum, qboolean *down)
{
	struct display *d = display;
 
	return Sys_Input_GetKeyEvent(d->inputdata, keynum, down);
}
 
void Sys_Video_GetMouseMovement(void *display, int *mousex, int *mousey)
{
	struct display *d = display;
 
	Sys_Input_GetMouseMovement(d->inputdata, mousex, mousey);
}
 
void Sys_Video_SetWindowTitle(void *display, const char *text)
{
	struct display *d;
 
	d = display;
 
	SetWindowTitles(d->window, text, (void *)-1);
}
 
unsigned int Sys_Video_GetWidth(void *display)
{
	struct display *d;
 
	d = display;
 
	return d->width;
}
 
unsigned int Sys_Video_GetHeight(void *display)
{
	struct display *d;
 
	d = display;
 
	return d->height;
}
 
qboolean Sys_Video_GetFullscreen(void *display)
{
	struct display *d;
 
	d = display;
 
	return d->fullscreen;
}
 
const char *Sys_Video_GetMode(void *display)
{
	struct display *d;
 
	d = display;
 
	return d->used_mode;
}
 
void Sys_Video_BeginFrame(void *display, unsigned int *x, unsigned int *y, unsigned int *width, unsigned int *height)
{
	struct display *d;
 
	d = display;
 
	*x = 0;
	*y = 0;
	*width = d->width;
	*height = d->height;
}
 
void Sys_Video_Update(void *display, vrect_t *rects)
{
	struct display *d = display;
 
	AROSMesaSwapBuffers(d->mesacontext);
}
 
void Sys_Video_GrabMouse(void *display, int dograb)
{
	struct display *d = display;
 
	if (!d->screen)
	{
		Sys_Input_GrabMouse(d->inputdata, dograb);
 
		if (dograb)
		{
			/* Hide pointer */
 
			SetPointer(d->window, d->pointermem, 16, 16, 0, 0);
		}
		else
		{
			/* Show pointer */
 
			ClearPointer(d->window);
		}
	}
}
 
void Sys_Video_SetGamma(void *display, unsigned short *ramps)
{
}
 
qboolean Sys_Video_HWGammaSupported(void *display)
{
	return 0; 
}
 
int Sys_Video_FocusChanged(void *display)
{
	return 0;
}


Far better using SDL's GL additions or even better ready made engines like Ogre, Crystal Space, etc...



Reference[edit]

slowdown when running multiple 3d apps: this happens because of the GL semaphore "ping pong" between the tasks which can cause like >10000 task switches (and GL context switches) per second.

Semaphores are evil! It you have two or more tasks (3d apps) competing for sem then they get into ping pong state when a task is preempted while he owns the sem which is very likely. From then on (until a task switch happens while the sem is *not* locked) what will happen is that only one (GL) call can be made by task #1, then task switch to task #2 happens, which also can only make one (GL) call, then task switch to task #1 happens, which can only make one (GL) call, then task switch to task #2 happens, etc.

One solution to prevent this would be to have some GrabGL/UngrabGL (or ObtainGL,ReleaseGL if that sounds better) functions to be used in 3D apps and then enclose big parts of GL rendering function calls with it. GrabGL would lock the GL sem and make sure context is correct. ReleaseGL would unlock the GL sem. Even better would be if GrabGL switched all the GL functions (through function table) to versions which which don't use semlock/contextcheck/semunlock at all.