Mainly, functions go in .cpp files and other stuff - like definitions goes in .h files.
I think a little project organization would go a long way in improving your project readability.
EDIT: After looking through your project more thoroughly I would suggest this format:
.cpp files
.....winMain.cpp (this is your windows code)
.....main.cpp (initialize, and render main function, clean up)
.....media.cpp (things like loading textures, music etc)
.....utility.cpp (useful functions, wrap(), fps(), 3dprintf() etc.)
.h files
.....global.h (global variables, and function prototypes, all includes)
.....media.h (media related variables only used in media.cpp)
.....utility.h (structure definitions, and prototypes)
Heres an example of my global header file
Code:
#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>
#include <gl\glext.h>
#include <iostream.h>
#include <fstream.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include "MediaLoader.h"
#include "music.h"
typedef struct {
bool down;
long time;
} key;
#ifdef MAIN_CPP
HGLRC hRC=NULL; // Permanent Rendering Context
HDC hDC=NULL; // Private GDI Device Context
HWND hWnd=NULL; // Holds Our Window Handle
HINSTANCE hInstance; // Holds The Instance Of The Application
key keys[256]; // Array Used For The Keyboard Routine
bool active=TRUE; // Window Active Flag Set To TRUE By Default
bool fullscreen=false; // Fullscreen Flag Set To Fullscreen Mode By Default
int g_winWidth = 480;
int g_winHeight = 320;
char * g_WindowTitle = "Space Pong";
long startTime = 0;
float g_FrameRate=0;
__int64 g_Frequency=0;
int g_FrameCount=0;
#else
extern g_winWidth;
extern g_winHeight;
extern HGLRC hRC;
extern HDC hDC;
extern float g_FrameRate;
extern __int64 g_Frequency;
extern int g_FrameCount;
extern long startTime;
extern key keys[256];
#endif
#include "font.h"
#ifdef GAME_CPP
GLFONT *fSystem = 0;
GLFONT *fMenu = 0;
PFNGLACTIVETEXTUREARBPROC glActiveTextureARB = NULL;
PFNGLMULTITEXCOORD2FARBPROC glMultiTexCoord2fARB = NULL;
PFNGLCLIENTACTIVETEXTUREARBPROC glClientActiveTextureARB = NULL;
#else
#endif
// prototypes
// game.cpp
void gameInit();
void splashScreen();
void MainLoop();
int menuSystem();
// main.cpp
GLvoid ReSizeGLSceneOrtho(int w, int h);
GLvoid ReSizeGLScene(GLsizei width, GLsizei height);
// utility.cpp
int cinstr(char * haystack, char *needle);
int wrap(int min, int max, int val);
float wrap(float min, float max, float val);
float deg2rad(float deg);
float timeScale(int ideal);
HRESULT InitTiming();
void Pause( int Milliseconds );
void FrameCount();
Pointers aside from project management -
Time based movement - I run your program at about 1700 fps, and spinning the box becomes rather sloppy because it spins way too fast. This code can solve that problem
Code:
////////////////////////////////
// frames per second modifier //
float timeScale(int ideal) {
return (ideal/(float)g_FrameRate);
}
// some where in your render function
if(keydown)
rotationVariable += 0.01 * timeScale(60); // 60 FPS ideal
// other...
if(movePlayer)
playerPos += 5 * timeScale(60); // etc.
Any time you incriment a variable, you should modify it based on an ideal FPS timing.
Also, you are using NeHe's keys[] boolean array, this is nice but I found altering the array type to be rather helpful - I've turned it into a struct
Code:
typdef struct {
bool down;
long int time;
} keystate;
During your WM_KEYDOWN case, you should assign the GetTickCount() to the time, and only allow down state changes based on an amount of time. ie:
Code:
if(GetTickCount() - keys[wParam].time > 100) {
keys[wParam].down = TRUE; // If So, Mark It As TRUE
keys[wParam].time = GetTickCount();
}
Any way, maybe that can help you out some how.