Code:
/*
Name: PsychoEngine
Author: Daniel Cook
Description: Game Creation Studio
Date: NULL
Copyright: 2004
License: This software is provided 'as-is' without warranty of any kind.
This software is provided with an 'Open-Source' license, to be used and
distributed freely, but under NO circumstances is this software to be sold
by persons other than members/representitves of PsychopathProductions with the
permission of their superior(s).
*/
// Include files
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>
#include <math.h>
#include "include.h"
//end include files
//set-up camera vectors
float PositionX = 0;
float PositionY = 0;
float PositionZ = 0;
float ViewX = 0;
float ViewY = 1;
float ViewZ = 8;
float UpX = 0;
float UpY = 0;
float UpZ = 1;
float VectorX;
float VectorY;
float VectorZ;
//end camera vector set-up
//CCamera gl_Camera;
HWND edit_box = NULL; //edit window handle
// Function Declarations
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ); //'define' the winproc call
VOID EnableOpenGL( HWND edit_box, HDC * hDC, HGLRC * hRC ); //'define' the OpenGL enable function call
VOID DisableOpenGL( HWND edit_box, HDC hDC, HGLRC hRC ); //'define' the OpenGL disable function call
// WinMain
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow )
{
WNDCLASS wc; //main window class
WNDCLASS ed; //edit window class
WNDCLASS mp; //model preview class
HWND hwnd; //main window handle
HDC hdc; //windows device context
HGLRC gl_hrc;//OGL device context
MSG msg; //message handle
BOOL bQuit = FALSE;
float theta = 0.0f;
//gl_Camera.PositionCamera(0, 0.0f, 0, 0, 1.0f, 0.5, 0, 0, 1);
// register window class
wc.style = NULL; //define window style
wc.lpfnWndProc = WndProc; //define the winproc
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance; //define the HINSTANCE
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION ); //set the icon
wc.hCursor = LoadCursor( NULL, IDC_ARROW ); //set the cursor
wc.hbrBackground = (HBRUSH)GetStockObject( GRAY_BRUSH ); //set the main window color
wc.lpszMenuName = "MAINMENU"; //menu name
wc.lpszClassName = "PsychoEngine"; //window class name
RegisterClass( &wc ); //regester the class
//regester edit class (same format as above :Þ)
ed.style = CS_OWNDC;
ed.lpfnWndProc = WndProc;
ed.cbClsExtra = 0;
ed.cbWndExtra = 0;
ed.hInstance = hInstance;
ed.hIcon = LoadIcon( NULL, IDI_APPLICATION );
ed.hCursor = LoadCursor( NULL, IDC_ARROW );
ed.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
ed.lpszMenuName = NULL;
ed.lpszClassName = "EDIT";
RegisterClass( &ed );
//regester model preview class (same format as above :Þ
mp.style = CS_OWNDC;
mp.lpfnWndProc = WndProc;
mp.cbClsExtra = 0;
mp.cbWndExtra = 0;
mp.hInstance = hInstance;
mp.hIcon = LoadIcon( NULL, IDI_APPLICATION );
mp.hCursor = LoadCursor( NULL, IDC_ARROW );
mp.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
mp.lpszMenuName = NULL;
mp.lpszClassName = "MODEL";
RegisterClass( &mp );
// create main window
hwnd = CreateWindow(
"PsychoEngine", "PsychoEngine | PsychopathProductions", //class, caption text
WS_TILEDWINDOW | WS_POPUPWINDOW | WS_VISIBLE, //style
0, 0, 800, 570, //x,y,width,height
NULL, NULL, hInstance, NULL );
HWND edit_box = NULL; //define edit_box handle
HWND model_box = NULL; //define model preview handle
LPARAM lParam;
RECT rect;
GetClientRect(hwnd,&rect);
//set up and create editbox
edit_box = CreateWindow("EDIT", "Edit Window",WS_CHILD | WS_CAPTION | WS_VISIBLE,
0, 0, 600, 516, hwnd, NULL, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
//setup and create model preview box
model_box = CreateWindow("MODEL", "Model Preview",WS_CHILD | WS_CAPTION | WS_VISIBLE,
600, 338, 192, 178, hwnd, NULL, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
//draw buttons
HWND button;
button = CreateWindow("BUTTON", "NPC's", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 616, 30, 64, 24, hwnd,(HMENU) 10, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
button = CreateWindow("BUTTON", "Player", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 708, 30, 64, 24, hwnd, (HMENU) 20, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
button = CreateWindow("BUTTON", "World Options", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 646, 58, 98, 24, hwnd, (HMENU) 30, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
button = CreateWindow("BUTTON", "Lighting", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 616, 86, 64, 24, hwnd, (HMENU) 40, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
button = CreateWindow("BUTTON", "Textures", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 708, 86, 64, 24, hwnd, (HMENU) 50, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
button = CreateWindow("BUTTON", "Weapons/Projectiles", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 620, 114, 148, 24, hwnd, (HMENU) 60, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
button = CreateWindow("BUTTON", "Attributes", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 616, 142, 64, 24, hwnd, (HMENU) 70, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
button = CreateWindow("BUTTON", "Camera", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 708, 142, 64, 24, hwnd, (HMENU) 80, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
button = CreateWindow("BUTTON", "Insert Brush", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 606, 184, 80, 24, hwnd, (HMENU) 90, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
button = CreateWindow("BUTTON", "Insert Entity", WS_VISIBLE |WS_CHILD | BS_PUSHBUTTON, 708, 184, 80, 24, hwnd, (HMENU) 100, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
// enable OpenGL for the edit window
EnableOpenGL( edit_box, &hdc, &gl_hrc );
// program main loop
while ( !bQuit ) {
// check for messages
if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) {
// handle or dispatch messages
if ( msg.message == WM_QUIT ) {
bQuit = TRUE;
}
else
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
} else {
void RenderScene();
{
int i=0;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The matrix
// OpenGL animation code
gluLookAt(PositionX, PositionY, PositionZ,
ViewX, ViewY, ViewZ,
UpX, UpY, UpZ);
glBegin (GL_TRIANGLES); // This is our BEGIN to draw
glColor3ub(255, 0, 0); // Make the top vertex RED
glVertex3f(0, -0.5, 0); // Here is the top point of the triangle
glColor3ub(0, 255, 0); // Make the left vertex GREEN
glVertex3f(-0.5, 0, 0); // Here is the left point of the triangle
glColor3ub(0, 0, 255); // Make the right vertex BLUE
glVertex3f(0.5, 0, 0); // Here is the right point of the triangle
glEnd();
for(float i = -50; i <= 50; i += 1)
{
// Start drawing some lines
glBegin(GL_LINES);
// Do the horizontal lines (along the X)
glVertex3f(-50, 0, i);
glVertex3f(50, 0, i);
// Do the vertical lines (along the Z)
glVertex3f(i, 0, -50);
glVertex3f(i, 0, 50);
// Stop drawing lines
glEnd();
}
SwapBuffers( hdc );
}
}
}
// shutdown OpenGL
DisableOpenGL( hwnd, hdc, gl_hrc );
// destroy the window explicitly
DestroyWindow( hwnd );
return msg.wParam;
}
// Window Procedure
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam )
{
HDC hdc; //define the hDC
static TEXTMETRIC textInfo; //define the textmetric
char szSTRING1[]="Menu"; //string 1
char szSTRING2[]="____________________"; //string2
PAINTSTRUCT paintStruct; //define the PAINTSTRUCT
hdc=NULL;
switch ( message )
{
case WM_CREATE:
break;
case WM_PAINT:
hdc = BeginPaint(hwnd, &paintStruct); //begin paint
SetTextColor(hdc, RGB(0, 0, 0)); //set text color
SetBkColor(hdc , RGB(128, 128, 128)); //set background color OF THE TEXT
TextOut(hdc, 676, 8, (szSTRING1), strlen(szSTRING1)); //put out string1
TextOut(hdc, 616, 156, (szSTRING2), strlen(szSTRING2)); //put out string2
EndPaint(hwnd, &paintStruct); //end paint
break;
case WM_CLOSE:
if(MessageBox (NULL, "Are you sure you want to close the program?\nAll un-saved data will be lost." , "Exiting...", 0 + MB_YESNO + MB_DEFBUTTON2 + MB_ICONQUESTION)==IDYES)
{
PostQuitMessage( 0 );
}
break;
return 0;
case WM_DESTROY:
break;
return 0;
case WM_KEYDOWN:
switch ( wparam )
{
case VK_UP:
VectorX = ViewX - PositionX;
VectorY = ViewY - PositionY;
VectorZ = ViewZ - PositionZ;
PositionX += VectorX * speed;
PositionZ += VectorZ * speed;
ViewX += VectorX * speed;
ViewZ += VectorZ * speed;
void RenderScene(); //render the scene after movement
break;
case VK_DOWN:
VectorX = ViewX - PositionX;
VectorY = ViewY - PositionY;
VectorZ = ViewZ - PositionZ;
PositionX += VectorX * -speed;
PositionZ += VectorZ * -speed;
ViewX += VectorX * -speed;
ViewZ += VectorZ * -speed;
void RenderScene(); //render the scene after movement
break;
}
break;
case WM_COMMAND:
//buttons
WORD wID,wNotify;
wID=LOWORD(wparam);
wNotify=HIWORD(wparam);
if (lparam)
{
//if a button was clicked
if (wNotify==BN_CLICKED)
{
//if a buttons id was clicked
if (wID==10)
{
MessageBox (NULL, "it works" , ":)", 0);
}
if (wID==20)
{
MessageBox (NULL, "it works" , ":)", 0);
}
if (wID==30)
{
MessageBox (NULL, "it works" , ":)", 0);
}
if (wID==40)
{
MessageBox (NULL, "it works" , ":)", 0);
}
if (wID==50)
{
MessageBox (NULL, "it works" , ":)", 0);
}
if (wID==60)
{
MessageBox (NULL, "it works" , ":)", 0);
}
if (wID==70)
{
MessageBox (NULL, "it works" , ":)", 0);
}
if (wID==80)
{
MessageBox (NULL, "it works" , ":)", 0);
}
if (wID==90)
{
MessageBox (NULL, "it works" , ":)", 0);
}
if (wID==100)
{
MessageBox (NULL, "it works" , ":)", 0);
}
}
}
//end buttons
return 0;
default:
return DefWindowProc( hwnd, message, wparam, lparam );
}
}
// Enable OpenGL
VOID EnableOpenGL( HWND edit_box, HDC * hdc, HGLRC * gl_hrc )
{
PIXELFORMATDESCRIPTOR pfd;
int iFormat;
// get the device context (DC)
*hdc = GetDC( edit_box );
// set the pixel format for the DC
ZeroMemory( &pfd, sizeof( pfd ) );
pfd.nSize = sizeof( pfd );
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; //GL flags
pfd.iPixelType = PFD_TYPE_RGBA; //pixel type
pfd.cColorBits = COLOR_DEPTH; //color depth
pfd.cDepthBits = SCREEN_DEPTH; //screen depth
pfd.iLayerType = PFD_MAIN_PLANE;
iFormat = ChoosePixelFormat( *hdc, &pfd ); //choose the best pixel format
SetPixelFormat( *hdc, iFormat, &pfd ); //set the pixel format
// create and enable the render context (RC)
glViewport(0,0,0,1);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,0/1, 1.0f, 150.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
*gl_hrc = wglCreateContext( *hdc );
wglMakeCurrent( *hdc, *gl_hrc );
}
// Disable OpenGL
VOID DisableOpenGL( HWND edit_box, HDC hdc, HGLRC gl_hrc )
{
wglMakeCurrent( NULL, NULL );
wglDeleteContext( gl_hrc );
ReleaseDC( edit_box, hdc ); //release from the drive context
}
defs.h