Mac OS X OpenGL and input module, using Carbon and AGL
- Copyright (C) 2005 Mathieu Olivier
+ Copyright (C) 2005-2006 Mathieu Olivier
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
static int scr_width, scr_height;
static AGLContext context;
-static WindowRef window;
+static WindowRef window;
void VID_GetWindowSize (int *x, int *y, int *width, int *height)
CGPoint winCenter;
SelectWindow(window);
- HideCursor();
+ CGDisplayHideCursor(CGMainDisplayID());
// Put the mouse cursor at the center of the window
GetWindowBounds (window, kWindowContentRgn, &winBounds);
if (vid_usingmouse)
{
CGAssociateMouseAndMouseCursorPosition(true);
- ShowCursor();
+ CGDisplayShowCursor(CGMainDisplayID());
vid_usingmouse = false;
}
}
}
+#define GAMMA_TABLE_SIZE 256
void VID_Finish (qboolean allowmousegrab)
{
qboolean vid_usemouse;
// handle the mouse state when windowed if that's changed
vid_usemouse = false;
- if (allowmousgrab && vid_mouse.integer && !key_consoleactive && !cls.demoplayback)
+ if (allowmousegrab && vid_mouse.integer && !key_consoleactive && !cls.demoplayback)
vid_usemouse = true;
if (!vid_activewindow)
vid_usemouse = false;
qglFinish();
qaglSwapBuffers(context);
}
+ VID_UpdateGamma(false, GAMMA_TABLE_SIZE);
}
-#define GAMMA_TABLE_SIZE 256
-int VID_SetGamma(unsigned short *ramps)
+int VID_SetGamma(unsigned short *ramps, int rampsize)
{
CGGammaValue table_red [GAMMA_TABLE_SIZE];
CGGammaValue table_green [GAMMA_TABLE_SIZE];
unsigned int i;
// Convert the unsigned short table into 3 float tables
- for (i = 0; i < GAMMA_TABLE_SIZE; i++)
+ for (i = 0; i < rampsize; i++)
table_red[i] = (float)ramps[i] / 65535.0f;
- for (i = 0; i < GAMMA_TABLE_SIZE; i++)
- table_green[i] = (float)ramps[i + GAMMA_TABLE_SIZE] / 65535.0f;
- for (i = 0; i < GAMMA_TABLE_SIZE; i++)
- table_blue[i] = (float)ramps[i + 2 * GAMMA_TABLE_SIZE] / 65535.0f;
+ for (i = 0; i < rampsize; i++)
+ table_green[i] = (float)ramps[i + rampsize] / 65535.0f;
+ for (i = 0; i < rampsize; i++)
+ table_blue[i] = (float)ramps[i + 2 * rampsize] / 65535.0f;
- if (CGSetDisplayTransferByTable(CGMainDisplayID(), GAMMA_TABLE_SIZE, table_red, table_green, table_blue) != CGDisplayNoErr)
+ if (CGSetDisplayTransferByTable(CGMainDisplayID(), rampsize, table_red, table_green, table_blue) != CGDisplayNoErr)
{
Con_Print("VID_SetGamma: ERROR: CGSetDisplayTransferByTable failed!\n");
return false;
return true;
}
-int VID_GetGamma(unsigned short *ramps)
+int VID_GetGamma(unsigned short *ramps, int rampsize)
{
CGGammaValue table_red [GAMMA_TABLE_SIZE];
CGGammaValue table_green [GAMMA_TABLE_SIZE];
unsigned int i;
// Get the gamma ramps from the system
- if (CGGetDisplayTransferByTable(CGMainDisplayID(), GAMMA_TABLE_SIZE, table_red, table_green, table_blue, &actualsize) != CGDisplayNoErr)
+ if (CGGetDisplayTransferByTable(CGMainDisplayID(), rampsize, table_red, table_green, table_blue, &actualsize) != CGDisplayNoErr)
{
Con_Print("VID_GetGamma: ERROR: CGGetDisplayTransferByTable failed!\n");
return false;
}
- if (actualsize != GAMMA_TABLE_SIZE)
+ if (actualsize != rampsize)
{
- Con_Printf("VID_GetGamma: ERROR: invalid gamma table size (%u != %u)\n", actualsize, GAMMA_TABLE_SIZE);
+ Con_Printf("VID_GetGamma: ERROR: invalid gamma table size (%u != %u)\n", actualsize, rampsize);
return false;
}
// Convert the 3 float tables into 1 unsigned short table
- for (i = 0; i < GAMMA_TABLE_SIZE; i++)
+ for (i = 0; i < rampsize; i++)
ramps[i] = table_red[i] * 65535.0f;
- for (i = 0; i < GAMMA_TABLE_SIZE; i++)
- ramps[i + GAMMA_TABLE_SIZE] = table_green[i] * 65535.0f;
- for (i = 0; i < GAMMA_TABLE_SIZE; i++)
- ramps[i + 2 * GAMMA_TABLE_SIZE] = table_blue[i] * 65535.0f;
+ for (i = 0; i < rampsize; i++)
+ ramps[i + rampsize] = table_green[i] * 65535.0f;
+ for (i = 0; i < rampsize; i++)
+ ramps[i + 2 * rampsize] = table_blue[i] * 65535.0f;
return true;
}
};
OSStatus carbonError;
Rect windowBounds;
- GDHandle screen;
AGLPixelFormat pixelFormat;
GLint attributes [32];
AsyncEvent_Quitting = false;
AsyncEvent_Collapsed = false;
- // Create the window
- SetRect(&windowBounds, 0, 0, width, height);
- OffsetRect(&windowBounds, 100, 100); // move it a bit towards the center of the screen
+ // Create the window, a bit towards the center of the screen
+ windowBounds.left = 100;
+ windowBounds.top = 100;
+ windowBounds.right = width + 100;
+ windowBounds.bottom = height + 100;
carbonError = CreateNewWindow(kDocumentWindowClass, kWindowStandardFloatingAttributes | kWindowStandardHandlerAttribute, &windowBounds, &window);
if (carbonError != noErr || window == NULL)
{
InstallWindowEventHandler (window, NewEventHandlerUPP (MainWindowEventHandler),
GetEventTypeCount(winEvents), winEvents, window, NULL);
- screen = GetGWorldDevice(GetWindowPort(window));
- if (screen == NULL)
- {
- Con_Printf("Unable to get GDevice for window\n");
- ReleaseWindow(window);
- return false;
- }
-
// Create and set pixel format
VID_BuildAGLAttrib(attributes, bpp == 32, fullscreen);
- pixelFormat = qaglChoosePixelFormat(&screen, 1, attributes);
+ pixelFormat = qaglChoosePixelFormat(NULL, 1, attributes);
if (pixelFormat == NULL)
{
Con_Printf("Unable to create pixel format\n");