So here it is: the first tutorial.
This tutorial will setup a simple screen/window and prepare everything for the final masterpiece.
Instead of starting to explain the Win32 API and the OpenGL API first, I give here and example on how to quickly create a skelton for an intro/demo using the GLTK, a small toolkit I wrote for this purpose.
GLTK takes care of everything required to setup a window/screen and I'll discuss this in details later when needed. First we have a look at what the high-level skeleton should look like, then we go deeper. Anyway, the source code is provided here anyway.
You will also notice that I make no use of the standard C type but rather personally defined types like CError and some others. These types have been defined in a file called dna.h (also provided here). This file just defines types with intelligent name.
First of all we'll discuss the high-level code found in the main.c file. Once the basics of the skeleton are understood, we can add more relevant stuff
/* RETRO-REMAKES TUTORIAL #1 - Screen/Window setup
Written by Stormbringer (stormbringer@retro-remakes.net)
This tutorial shows how to use the gltk api:
a small Graphic Library Toolkit written on purpose for setting up a screen and some drawing properties for OpenGL
Here you will learn the basics of setting up a screen/window with OpenGL capabilities and intercept basic information,
such as mouse clicks, paint requests and time changes
*/
/*
include the GLTK (Graphics Library Toolkit)
*/
#include "..\gltk\gltk.h"
/*
our screen "object" that holds the properties of our screen/window
*/
GLTKScreenProperties screenProperties;
/*
intro_on_mouse_left_down()
user pressed the left mouse button
*/
CError intro_on_mouse_left_down(pCVoid userData)
{
/* quit */
gltk_screen_quit();
/* done */
return(0);
}
/*
intro_on_vsync()
this method works like a timer interrupt. we will use it to track time changes and update the animation of or elements, etc
*/
CError intro_on_vsync(pCVoid userData, CFloat64 deltaTime)
{
return(0);
}
/*
intro_on_paint()
this method is used to paint the graphic elements on screen
*/
CError intro_on_paint(pCVoid userData)
{
/* clean the screen
*/
/* black background */
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
/* clear depth buffer with default value */
glClearDepth(1.0f);
/* disable the depth test */
glDisable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
/* disable any clippin */
glDisable(GL_SCISSOR_TEST);
/* draw some stuff here...
*/
/* done */
return(0);
}
/*
entry point
*/
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
/* hide cursor */
gltk_screen_show_cursor(FALSE);
/* init screen structure */
memset(&screenProperties,0,C_SIZE_OF(screenProperties));
/* name of the */
screenProperties.name="My new cracktro";
/* define window dimensions
*/
screenProperties.width=640;
screenProperties.height=480;
/* request vsync
NOTE: in order for this option to work fine, you need to set your graphics driver Vertical Sync option on "Application Controlled"
*/
screenProperties.vsync=TRUE;
/* request refresh rate
NOTE: this will only work 100% in full screen mode, if the graphics card is capable of it
*/
screenProperties.vsyncFPS=60;
/* flag for window mode/full screen mode
*/
screenProperties.fullScreen=FALSE;
/* our method for painting the screen
*/
screenProperties.paintMethod=intro_on_paint;
/* our method for managing the time (where we change animation, etc)
*/
screenProperties.vsyncMethod=intro_on_vsync;
/* our method to intercept the left mouse button
*/
screenProperties.leftMouseDown=intro_on_mouse_left_down;
/* open the screen/window using the give properties
*/
if (gltk_screen_open(&screenProperties))
{
/* run the main loop, intercept system events, etc
*/
gltk_screen_run_loop(&screenProperties);
/* close screen window
*/
gltk_screen_close(&screenProperties);
}
/* exit and return code to system */
return(0);
}