here is my winmain
Code:
int WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
bool done = false;
//The next part will be a message box that pops up to ask the user if he/she wishes to run in
//Fullscreen mode.
if(MessageBox(NULL, "Would you like to run in Full Screen Mode", "Ti-X Engine", MB_YESNO | MB_ICONQUESTION)==IDNO)
{
fullscreen = false; //runs in windowed mode (since the fullscreen way up there has been set to true by default)
}
//This is where we create the OpenGL window (using the creat_gl_window function we wrote earlier)
if(!create_gl_window("Ti-X WGL Skeleton", 1280, 1024, 16, fullscreen))
{
return 0; //Quit if the window was not able to creat
}
while (!done) //While we're not done continue in the while loop (this is actually our main loop)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message==WM_QUIT) //If recieve a message telling to quit then set done to true
{
done = true; //This will make the program quit
}
else //if we're not done then handle the messages.
{
TranslateMessage(&msg); //Translate message
DispatchMessage(&msg); //Dispatch messate
}
}
else
{
if(program_status)
{
if (keys[VK_ESCAPE]) //If the escape key is pressed
{
done = true; //Done to true, so we quit
}
else //if not then continue drawing our stuff.
{
draw_scene(); //here we finally call the draw_scene function which will draw our stuff
SwapBuffers(hDC); //Since we're using double buffering we need this to swap the buffer
if (keys['L'] && !l_stat)
{
l_stat = true;
light = !light;
if (!light)
{
glDisable(GL_LIGHTING);
}
else
{
glEnable(GL_LIGHTING);
}
}
if (!keys['L'])
{
l_stat = false;
}
if (keys['W'])
{
camera_x -= (float)sin(-mouse_y * piover180) * 0.05f;
camera_z -= (float)cos(-mouse_y * piover180) * 0.05f;
}
if (keys['S'])
{
camera_x += (float)sin(-mouse_y * piover180) * 0.05f;
camera_z += (float)cos(-mouse_y * piover180) * 0.05f;
}
if (keys['A'])
{
camera_x -= (float)cos(mouse_y * piover180) * 0.05f;
camera_z -= (float)sin(mouse_y * piover180) * 0.05f;
}
if (keys['D'])
{
camera_x += (float)cos(mouse_y * piover180) * 0.05f;
camera_z += (float)sin(mouse_y * piover180) * 0.05f;
}
if (keys[VK_LEFT])
{
direction += 0.02f;
rotate_z = direction;
}
if (keys[VK_RIGHT])
{
direction -= 0.02f;
rotate_z = direction;
}
if (keys[VK_PRIOR])
{
height += 0.01f;
}
if (keys[VK_NEXT])
{
height -= 0.01f;
}
}
}
//This next bit of code will alow you to switch from windowed to fullscreen mode.
if(keys[VK_F1])
{
keys[VK_F1] = false; // If f1 is pressed make false
kill_gl_window();
fullscreen = !fullscreen;
// Recreate our GL window
if (!create_gl_window("Ti-x WGL Framework", 1280, 1024, 16, fullscreen))
{
return 0;
}
}
}
}
//shut down
kill_gl_window(); //Kill window
return(msg.wParam); //Exit the program
}
here is my WndProc
Code:
//this callback function will handle the message out put by window.
LRESULT CALLBACK WndProc( HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
static HMENU hMenu;
//POINT point;
switch(uMsg) //This will check for all sorts of windows message.
{
case WM_MOUSEMOVE:
{
mouse_y = LOWORD(lParam);
mouse_x = HIWORD(lParam);
}
case WM_INITDIALOG:
{
hMenu = LoadMenu(GetModuleHandle(NULL),//Load Menu
MAKEINTRESOURCE(IDR_MENU2));
hMenu = GetSubMenu(hMenu,0);//Get Sub Menu
return 0;
}
case WM_RBUTTONDOWN:
{
//point.x = LOWORD(lParam);
//point.y = HIWORD(lParam);
TrackPopupMenu(hMenu,TPM_LEFTALIGN | TPM_RIGHTBUTTON,
mouse_y,mouse_x,NULL,hWnd,NULL);
return 0;
}
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case ID_COUCHCOLOR_RED:
{
couchRGB[0] = 1.0;
couchRGB[1] = 0.0;
couchRGB[2] = 0.0;
return 0;
}
case ID_COUCHCOLOR_WHITE:
{
couchRGB[0] = 1.0;
couchRGB[1] = 1.0;
couchRGB[2] = 1.0;
return 0;
}
case ID_COUCHCOLOR_BLUE:
{
couchRGB[0] = 0.0;
couchRGB[1] = 0.0;
couchRGB[2] = 1.0;
return 0;
}
case ID_TVCOLOR_GREEN:
{
tv_setRGB[0] = 0.0;
tv_setRGB[1] = 1.0;
tv_setRGB[2] = 0.0;
return 0;
}
case ID_TVCOLOR_RED:
{
tv_setRGB[0] = 1.0;
tv_setRGB[1] = 0.0;
tv_setRGB[2] = 0.0;
return 0;
}
case ID_TVCOLOR_YELLOW:
{
tv_setRGB[0] = 0.7;
tv_setRGB[1] = 0.5;
tv_setRGB[2] = 0.0;
return 0;
}
case ID_TVSTANDCOLOR_WHITE:
{
tv_standRGB[0] = 1.0;
tv_standRGB[1] = 1.0;
tv_standRGB[2] = 1.0;
return 0;
}
case ID_TVSTANDCOLOR_RED:
{
tv_standRGB[0] = 1.0;
tv_standRGB[1] = 0.0;
tv_standRGB[2] = 0.0;
return 0;
}
case ID_TVSTANDCOLOR_GREY:
{
tv_standRGB[0] = 0.2;
tv_standRGB[1] = 0.2;
tv_standRGB[2] = 0.2;
return 0;
}
case ID_TEATABLECOLOR_GREY:
{
tea_tableRGB[0] = 0.0;
tea_tableRGB[1] = 1.0;
tea_tableRGB[2] = 0.0;
return 0;
}
case ID_TEATABLECOLOR_BLUE:
{
tea_tableRGB[0] = 0.1;
tea_tableRGB[1] = 0.1;
tea_tableRGB[2] = 1.0;
return 0;
}
case ID_TEATABLECOLOR_BROWN:
{
tea_tableRGB[0] = 0.07;
tea_tableRGB[1] = 0.037;
tea_tableRGB[2] = 0.007;
return 0;
}
case ID_ROOMCOLOR_RED:
{
wallRGB[0] = 0.6;
wallRGB[1] = 0.1;
wallRGB[2] = 0.0;
return 0;
}
case ID_ROOMCOLOR_WHITE:
{
wallRGB[0] = 1.0;
wallRGB[1] = 1.0;
wallRGB[2] = 1.0;
return 0;
}
case ID_ROOMCOLOR_GREEN:
{
wallRGB[0] = 0.0;
wallRGB[1] = 1.0;
wallRGB[2] = 0.0;
return 0;
}
case ID_PICTUREFRAMECOLOR_WHITE:
{
picture_frameRGB[0] = 1.0;
picture_frameRGB[1] = 1.0;
picture_frameRGB[2] = 1.0;
return 0;
}
case ID_PICTUREFRAMECOLOR_RED:
{
picture_frameRGB[0] = 1.0;
picture_frameRGB[1] = 0.0;
picture_frameRGB[2] = 0.0;
return 0;
}
case ID_PICTUREFRAMECOLOR_GREEN:
{
picture_frameRGB[0] = 0.0;
picture_frameRGB[1] = 1.0;
picture_frameRGB[2] = 0.0;
return 0;
}
case ID_WINDOWFRAMECOLOR_RED:
{
windowRGB[0] = 1.0;
windowRGB[1] = 0.0;
windowRGB[2] = 0.0;
return 0;
}
case ID_WINDOWFRAMECOLOR_GREEN:
{
windowRGB[0] = 0.0;
windowRGB[1] = 1.0;
windowRGB[2] = 0.0;
return 0;
}
case ID_WINDOWFRAMECOLOR_ORANGE:
{
windowRGB[0] = 0.4;
windowRGB[1] = 0.3;
windowRGB[2] = 0.0;
return 0;
}
return 0;
}
return 0;
}
case WM_ACTIVATE:
{
if(!HIWORD(wParam)) //Check if Program is in Minimize state
{
program_status = true; //Program is still active
}
else
{
program_status = false; //Program is going into Minimize state
}
return 0;
}
case WM_SYSCOMMAND:
{
switch (wParam)
{
case SC_SCREENSAVE: //In case that screensaver is trying to start
case SC_MONITORPOWER: //In case that monitor going into power saving mode
return 0; //<< this will prevent the above from happening.
}
break;
}
case WM_CLOSE: //If the X at the top right hand corner is pressed
{
DestroyMenu(hMenu);
EndDialog(hWnd,0);
PostQuitMessage(0); //Post a Quit Message
return 0;
}
case WM_KEYDOWN: //If a key is being pressed
{
keys[wParam] = true; //If a key is being pressed mark it as true
return 0;
}
case WM_KEYUP: //If a key is released
{
keys[wParam] = false; //If a key is released mark as false
return 0;
}
case WM_SIZE: // If the Resize button is pressed
{
resize_window(LOWORD(lParam), HIWORD(lParam)); //LoWord = width HiWord = Height
return 0;
}
return 0;
}
//Of course there are more windows message we don't give a damn about so we can pass it through this:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}