2.- Google for them if you have DevC, they are included in MSVC so you can start now if you use MSVC
3.- More than allegro, less than directx. Anyhow, you have to do the windows & message handling (allegro does this for you) and that's a lot of lines.
4.- OpenGL just draws lit triangles and does the transforms. You have to provide the rest. Check AllegroGL: You can use Allegro's features and render using OpenGL, that is, using Keyboard, sound & timers from allegro and GFX from OpenGL.
Code:
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <gl\gl.h>
#include <gl\glu.h>
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600
#define SCREEN_DEPTH 16
bool g_bFullScreen = TRUE;
HWND g_hWnd;
RECT g_rRect;
HDC g_hDC;
HGLRC g_hRC;
HINSTANCE g_hInstance;
// WinProc to manage messages:
LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
// Rendering function:
void RenderScene();
/* Funciones */
void ChangeToFullScreen()
{
DEVMODE dmSettings;
memset(&dmSettings,0,sizeof(dmSettings));
if(!EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&dmSettings))
{
MessageBox(NULL, "Could Not Enum Display Settings", "Error", MB_OK);
return;
}
dmSettings.dmPelsWidth = SCREEN_WIDTH;
dmSettings.dmPelsHeight = SCREEN_HEIGHT;
int result = ChangeDisplaySettings(&dmSettings,CDS_FULLSCREEN);
if(result != DISP_CHANGE_SUCCESSFUL)
{
MessageBox(NULL, "Display Mode Not Compatible", "Error", MB_OK);
PostQuitMessage(0);
}
}
HWND CreateMyWindow(LPSTR strWindowName, int width, int height, DWORD dwStyle, bool bFullScreen, HINSTANCE hInstance)
{
HWND hWnd;
WNDCLASS wndclass;
memset(&wndclass, 0, sizeof(WNDCLASS));
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WinProc;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
wndclass.lpszClassName = "GameTutorials";
RegisterClass(&wndclass);
if(bFullScreen && !dwStyle)
{
dwStyle = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
ChangeToFullScreen();
ShowCursor(FALSE);
}
else if(!dwStyle)
dwStyle = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
g_hInstance = hInstance;
RECT rWindow;
rWindow.left = 0;
rWindow.right = width;
rWindow.top = 0;
rWindow.bottom = height;
AdjustWindowRect( &rWindow, dwStyle, false);
hWnd = CreateWindow("GameTutorials", strWindowName, dwStyle, 0, 0,
rWindow.right - rWindow.left, rWindow.bottom - rWindow.top,
NULL, NULL, hInstance, NULL);
if(!hWnd) return NULL;
ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);
SetFocus(hWnd);
return hWnd;
}
WPARAM MainLoop()
{
MSG msg;
while(1) {
// Check if windows message...
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if(msg.message == WM_QUIT)
// Message was not quit...
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
// If no messages...
{
/* Render */
RenderScene();
}
}
return(msg.wParam);
}
bool bSetupPixelFormat(HDC hdc)
{
PIXELFORMATDESCRIPTOR pfd;
int pixelformat;
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.dwLayerMask = PFD_MAIN_PLANE;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = SCREEN_DEPTH;
pfd.cDepthBits = SCREEN_DEPTH;
pfd.cAccumBits = 0;
pfd.cStencilBits = 0;
if ( (pixelformat = ChoosePixelFormat(hdc, &pfd)) == FALSE )
{
MessageBox(NULL, "ChoosePixelFormat failed", "Error", MB_OK);
return FALSE;
}
if (SetPixelFormat(hdc, pixelformat, &pfd) == FALSE)
{
MessageBox(NULL, "SetPixelFormat failed", "Error", MB_OK);
return FALSE;
}
return TRUE;
}
void SizeOpenGLScreen(int width, int height)
{
if (height==0)
{
height=1;
}
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height, 1 ,150.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void InitializeOpenGL(int width, int height)
{
g_hDC = GetDC(g_hWnd);
if (!bSetupPixelFormat(g_hDC))
PostQuitMessage (0);
g_hRC = wglCreateContext(g_hDC);
wglMakeCurrent(g_hDC, g_hRC);
SizeOpenGLScreen(width, height);
}
void Init(HWND hWnd)
{
g_hWnd = hWnd;
GetClientRect(g_hWnd, &g_rRect);
InitializeOpenGL(g_rRect.right, g_rRect.bottom);
}
void RenderScene()
{
int i=0;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(0, 0, 6, 0, 0, 0, 0, 1, 0);
// Draw a triangle:
glBegin (GL_TRIANGLES);
glVertex3f(0, 1, 0);
glVertex3f(-1, 0, 0);
glVertex3f(1, 0, 0);
glEnd();
SwapBuffers(g_hDC);
}
void DeInit()
{
if (g_hRC)
{
wglMakeCurrent(NULL, NULL);
wglDeleteContext(g_hRC);
}
if (g_hDC)
ReleaseDC(g_hWnd, g_hDC);
if(g_bFullScreen)
{
ChangeDisplaySettings(NULL,0);
ShowCursor(TRUE);
}
UnregisterClass("GameTutorials", g_hInstance);
PostQuitMessage (0);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hprev, PSTR cmdline, int ishow)
{
HWND hWnd;
if(MessageBox(NULL, "Click Yes to go to full screen (Recommended)", "Options", MB_YESNO | MB_ICONQUESTION) == IDNO)
g_bFullScreen = FALSE;
hWnd = CreateMyWindow("www.GameTutorials.com - First OpenGL Program", SCREEN_WIDTH, SCREEN_HEIGHT, 0, g_bFullScreen, hInstance);
if(hWnd == NULL) return TRUE;
Init(hWnd);
return MainLoop();
}
LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam)
{
LONG lRet = 0;
PAINTSTRUCT ps;
switch (uMsg)
{
case WM_SIZE:
if(!g_bFullScreen)
{
SizeOpenGLScreen(LOWORD(lParam),HIWORD(lParam));
GetClientRect(hWnd, &g_rRect);
}
break;
case WM_PAINT:
BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;
case WM_KEYDOWN:
if(wParam == VK_ESCAPE)
DeInit();
break;
case WM_DESTROY:
DeInit();
break;
default:
lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
break;
}
return lRet;
}
Btw, the 90% of code is the damned Windows stuff.