Dark Bit Factory & Gravity
PROGRAMMING => Coding tutorials => Topic started by: stormbringer on June 13, 2009
-
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);
}
-
It builds and compiles fine in visual studio 2008 :-)
I got a nice empty borderless window, this looks cool. I need to find some tutorials of using visual studio next as I never used this IDE before but in fairness your framework looks nice to use.
-
Nice one. Source code looks good. Seems that I need to re-install the Visual
Suite again on my comp.
K++
-
Great stuff I have slways wanted to learn this and now I can :updance:
-
work fine apart from 2 warning when i compiled the files.
Good to see a New Tutorial in our Forum :)
-
These tutorials are a great idea....keep it up stormbringer I hope to see lots more
When I get time I'll be having a play with this
-
Hello all!
New here and this is my first post. My first question might be stupid but where do I get this gltk ? Or
is there something I'm missing. I tried to google for it but didn't find anything. Is there an svn-server or somthing where I could get it?
cheers
Patrick
-
@patrick: welcome here mate! the source code is in the zip file in my first post here, look at the top.
-
oh, how did I miss that :D. Well, thanks stormbringer. Quite a useful pack of functionality got to say :)
-
feel free to use it and learn more here through the tutorials. questions & comments are welcome
-
i had to harash you a lot of starting this tutorials, but you finnaly stated it, good job my friend.
greetings from the Gambia
-
Hi all, just given this a try, thanks a lot. Successful so far, though it took me a while to realise I'd need to register in order to see the download link.
-
Hi
Great tutorial the only problem is that when I tried to biuld the soulution i Got these errors:
Warning 1 warning LNK4076: invalid incremental status file '.\Debug/TUTORIAL1_Setup.ilk'; linking nonincrementally TUTORIAL1_Setup TUTORIAL1_Setup
Error 2 fatal error LNK1104: cannot open file 'LIBCD.lib' TUTORIAL1_Setup TUTORIAL1_Setup
Does anyone know how to fix this?
james
-
@James: what version/compiler do you use?
-
Hi
Im using visual studio 2008 Proffesional when i press build the errors come up I checked over the code and i dont see any errors and i know other people have got it work with visual studio so Im a bit confused I know my laptop has a bit of a personality problem so it could just be it acting up
James
edit(scratch that i individually compiled all of the .c files then built it and now i just get two warnings is that normal)
-
@James_wright_1990: Works fine for me under MSVC 2008, first delete all files inside "Debug" folder, and just let MSVC convert "TUTORIAL1_Setup.dsp" and it will compile fine on debug/release mode.
-
Cheers for that got it sorted now all working fine thanks for the help. Builds fine great tutorial.
James
-
Great tutorial man!
Downloaded the template and it compiles fins under VS6. :goodpost:
Seems to have some difficulties under VS2010, though.
Thanks again!
-
Hi! :)
Very good tutorial!
I just found it.. :) and it's just what I needed :) Thx!
-
:inspired:Can I use this for a mac?
I own a nice little and quiet g4-mac-mini with osx 10.4.
It has a G4 PPC 1,5Ghz and an ATI 9200 (64MB). That should be enough to made some old cracktros/intros run at 80fps.
Perhaps it it possible to use some techniques the OS has build in, like core-image etc.
Some software seems to use this and produces a real stutterfee image movement or call it scrolling.
Thx
Doc
-
https://web.archive.org/web/20090219062029/http://www.cocoalab.com:80/BecomeAnXcoder(Tiger).pdf
This is what I found, is it worth to read and try to understand that, or is this the wrong way if I want
to do some code with the goal of making some cracktro-remakes in OSX/PPC for my G4-Mini 10.4.
This seems to be a good start:
https://developer.apple.com/library/content/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_overview/dq_overview.html#//apple_ref/doc/uid/TP30001066-CH202-TPXREF101