Friday, August 29, 2008

Starting Game Programming -Part 4

hi gamers,
Lets continue from where we left.....

Now taking the windows and opengl

opengl + win32 =wiggle

1) we will create handle for brush for filling and painting

HBRUSH hbluebrush , hredbrush;

then these are created in winmain

hbluebrush = CreateSolidBrush( RGB ( 0, 0 ,255 ) );
hredbrush = CreateSolidBrush( RGB (255, 0 ,0 ) );

eg use of it is to set the window background like:

wc.hbrBackground = hBlueBrush;



2) We used auxInitPosition for console but in windows we use

hWnd = CreateWindow(
lpszAppName,
lpszAppName,
WS_OVERLAPPED,
...
...

);

The actual painting is handled by WM_PAINT in WndProc function

opengl command -> opengl rendering context -> windows rendering context -> opengl output window.

The three most used
functions with regard to the rendering context are

HGLRC wglCreateContext(HDC hDC);
BOOL wglDeleteContext(HGLRC hrc);
BOOL wglMakeCurrent(HDC hDC, HGLRC hrc);


function wglCreateContext(HDC hDc ) takes a handle to a window GDI device context
and returns a handle to opengl rendering context.

function wglDeleteContext( HGLRC hrc ) takes rendering context as parameter

function wglMakeCurrent( HDC hDc , HGLRC hrc ) is used to make the rendering context suitable for that device context.Both device and

rendering context should
have the same characteristics such as pixel format..

3)Two message are involved in creating and destroying of rendering context

WM_CREATE
WM_DESTROY


LRESULT CALLBACK WndProc(HWND hWnd ,..)
{
static HGLRC hRC;
static HDRC hDC;

switch(msg)
{
case WM_CREATE:
hDeviceContext = GetWnd(hWnd);
hRenderContext =wglCreateContext(hDC);
wglMakeCurrrent = wglMakeCurrent(hDC ,hRC );

break;

case WM_DESTROY:

wglMakeCurrent(hDc,NULL);
wglDeleteContext(hRC);

PostQuitMessage(0);

break;

}

Wednesday, August 20, 2008

Starting The Game Programming -Part3

hi gamers,
The opengl basic concept continues...

In order to resize the drawing according to the size of the window opengl
uses glortho(left, right, bottom, top , near, far) function...

void glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
x,y is the lower right corner of the screen
Usually x and y will both be zero, but you can use viewports to render more than one drawing in different areas of a window. The viewport defines the area within the window in actual screen coordinates that OpenGL can use to draw in

NOTE:
OpenGL’s default method for counting the x coordinate is the same; however, it counts the y coordinate from bottom to top—just the opposite of Windows

its like eg:

here the function Changesize( w, h) w=width and h = height is the updated height
when the window gets resized
void CALLBACK ChangeSize( GLsizei w , GLsizei h)
{
if ( h ==0 )
{
h = 1;
}

glViewport (0 , 0 ,w ,h);
glLoadIdentity();

//when the window gets resized vertically then the top portion is updated
if( w <>
glOrtho( 0.0f , 250.0f,0.0f ,250.0f * h/w ,1.0f ,-1.0f);
else
//when the window gets resized horizontally the the right portion is updated
glOrtho( 0.0f , 250.0f * w/h ,0.0f ,250.0f ,1.0f ,-1.0f);

}

Monday, August 18, 2008

Starting The Game Programming -Part2

Hi gamers,
Lets continue from where we left..we will be concentrating mainly on opengl way of
programming for now...

opengl function naming convention :

glcolor3f implies :-

gl =library name , color = root command , 3 = number of arguments ,
f = argument type.

OpenGL has not a single function or command relating to window or screen management

AUX = Platform I/O, the Easy Way


Before drawing anything we specify :-
Type of window = eg buffered window = means all drawing commands are performed on
the window displayed.

eg:double buffered = it is used in animation...where drawing command are actually
executed to create a scene off screen , then quickly swapped into view on the window.


glInitWindow( " " ) , glinitdisplaymode ( GL_SINGLE | GL_RGBA )

glinitposition( x, y , width ,height )


CALLBACK = we’re going to tell the AUX library to call this function whenever the window needs updating.

glFlush = the glFlush() function simply tells OpenGL that it
should proceed with the drawing instructions supplied thus far before waiting for any more drawing commands.OpenGL commands and statements often are queued up until the OpenGL server processes several “requests” at once. This improves performance, especially when constructing complex objects. Drawing is accelerated because the slower graphics hardware is accessed less often for a given set of drawing instructions.


glMainLoop( FunctionName )
FunctioName = Its the function that is used for drawing.....
function simply keeps the program going until it’s terminated by closing the window. This function’s single argument is a pointer to another function it should call whenever the window needs updating.This callback function will be called when the window is first displayed, when the window is moved or resized, and when the window is uncovered by some other window.

Thursday, August 14, 2008

Starting The Gaming Programming-Part1

Hi gamers,
Let me start gaming programming with knowing some game terminology .its the starting thing we should know...

some Basic stuffs for game terminology:

When we talk about 3D its actually combination of 2D and perspective projection.
3D = 2D + perspective.

Perspective projection is like we what we see in real world:
1) Objects closer to eyes appears larger
2)Objects far away from viewer appears smaller.

Whatever we want to draw in screen which is having only two dimension but using perspective color changes,lighting,textures,shading add together to the perception
of three dimensional image.So..
perpepective + colors + shading + lighting +texture ~= 3D image


Clipping area = the area in co-ordinate system which occupies in screen co-ordinates is known as clipping area..Its basically a translation from one to another.

ViewPort = Rarely It happens that the clipping areas width and height matches with the height and width of windows area.Therefore it has to be mapped from logical co-ordinate system to screen pixel.This is called ViewPort...its basically clients window area for drawing.

SOme time the viewport can be larger or smaller when compared to clipping area.


Primitives = these are basically two dimensional ojects such lines,points and polygons..These primitives are assembled to create 3d objects in 3d space.


In 3d dimension we (x,y, z)
Z can we pointing outwards or pointing inwards...depending upon convention taken
like right hand or left hand system.
Right hand system = thumb is x, index in y and middle finger is Z and is pointing
outward.

left hand system = thumb is x, index in y and middle finger is Z and is pointing
inward.

Far Clipping Plane = It indiactes how far we can see....

Viewinf Plane = It basically refer to the screen....


Viewing volume = Space between the near clipping plane and far clipping plane
is known as viewing volume..