From 950aa6929386d478f5a45739c4abd70500f1fef7 Mon Sep 17 00:00:00 2001 From: Dennis Peeten Date: Tue, 27 May 2008 16:58:31 +0000 Subject: --- matchblox/common/message_input.h | 2 + matchblox/common/wiimote_utils.cpp | 21 ++-- matchblox/engine/C_3DObject.cpp | 10 +- matchblox/engine/C_3DObject.h | 4 +- matchblox/engine/C_Block.cpp | 10 +- matchblox/engine/C_Block.h | 2 +- matchblox/engine/C_Box.cpp | 8 +- matchblox/engine/C_Box.h | 2 +- matchblox/engine/C_Hand.cpp | 8 +- matchblox/engine/C_Log.h | 4 +- matchblox/engine/C_MatchBloxEngine.cpp | 212 +++++++++++++++++++++++++++++---- matchblox/engine/C_MatchBloxEngine.h | 21 +++- matchblox/main.cpp | 116 +++++++----------- matchblox/matchblox.vcproj | 8 ++ 14 files changed, 297 insertions(+), 131 deletions(-) diff --git a/matchblox/common/message_input.h b/matchblox/common/message_input.h index 646ec3a..fef13f7 100644 --- a/matchblox/common/message_input.h +++ b/matchblox/common/message_input.h @@ -47,6 +47,7 @@ enum wiimote_btns }; struct rawdot { int rx, ry; }; +struct smoothsbdot { double sx, sy; }; //raw smoothed dots struct input_payload_wiimote { @@ -58,6 +59,7 @@ struct input_payload_wiimote relY, //relative y coordinate of mouse cursor [0,1] Zdist; //distance from sensorbar in mm struct rawdot irdot[4]; + struct smoothsbdot SensorBarDot[2]; //grouped averaged and smoothed ir sensorbar dots char posDataValid; //is true when the position data is valid (nrdots > 1) }; diff --git a/matchblox/common/wiimote_utils.cpp b/matchblox/common/wiimote_utils.cpp index 6d0d7a0..7c39019 100644 --- a/matchblox/common/wiimote_utils.cpp +++ b/matchblox/common/wiimote_utils.cpp @@ -42,11 +42,11 @@ void AbstractWiimote::FillWiimoteMsgPayload(input_payload_wiimote &f_payload, do double AbstractWiimote::CalcZDistInMM(Vect3D_t f_Dot[2], double f_dLedDist) { - double l_dX = f_Dot[0].x - f_Dot[1].x, //difference in x coordinates - l_dY = f_Dot[0].y - f_Dot[1].y, //difference in y coordinates - l_dDotDist = sqrt(l_dX*l_dX + l_dY*l_dY), //distance between ir dots (in camera pixels) - l_dDotAngle = g_dWiimoteRadPerPixel * l_dDotDist; //the angle between the lines from the camera through the two - //ir dots (in radians) + double l_dX = f_Dot[0].x - f_Dot[1].x, //difference in x coordinates + l_dY = f_Dot[0].y - f_Dot[1].y, //difference in y coordinates + l_dDotDist = sqrt(l_dX*l_dX + l_dY*l_dY), //distance between ir dots (in camera pixels) + l_dDotAngle = g_dWiimoteRadPerPixel * l_dDotDist; //the angle between the lines from the camera through the two + //ir dots (in radians) return (0.5*f_dLedDist)/tan(0.5*l_dDotAngle); //the distance between the sensorbar and wiimote (in mm) } @@ -209,13 +209,18 @@ bool AbstractWiimote::CalcWiimoteRelativeCursorPos(input_payload_wiimote &f_Wiim if (!FindSensorBarDots(f_WiimoteMsg.irdot, f_WiimoteMsg.nrdots, l_Dot)) return false; + //smooth the ir dots + l_Dot[0] = m_pSensBarDotSmoother[0]->Smooth(l_Dot[0]); + l_Dot[1] = m_pSensBarDotSmoother[1]->Smooth(l_Dot[1]); + + //store the raw smoothed sensor bar dots in the message payload (used for head tracking) + f_WiimoteMsg.SensorBarDot[0].sx = l_Dot[0].x; f_WiimoteMsg.SensorBarDot[0].sy = l_Dot[0].y; + f_WiimoteMsg.SensorBarDot[1].sx = l_Dot[1].x; f_WiimoteMsg.SensorBarDot[1].sy = l_Dot[1].y; + //invert the x and y axis to correspond to screen coordinates l_Dot[0] = l_CameraRes - l_Dot[0]; l_Dot[1] = l_CameraRes - l_Dot[1]; - //smooth the ir dots - l_Dot[0] = m_pSensBarDotSmoother[0]->Smooth(l_Dot[0]); - l_Dot[1] = m_pSensBarDotSmoother[1]->Smooth(l_Dot[1]); //calc the angle of the wiimote with respect to the sensorbar Vect3D_t l_delta = l_Dot[1] - l_Dot[0]; double theta; diff --git a/matchblox/engine/C_3DObject.cpp b/matchblox/engine/C_3DObject.cpp index b9186cd..24c759a 100644 --- a/matchblox/engine/C_3DObject.cpp +++ b/matchblox/engine/C_3DObject.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -78,15 +79,22 @@ void C_3DObject::TransRotateScale() glScaled(m_Scale.x, m_Scale.y, m_Scale.z); } -void C_3DObject::Render() +void C_3DObject::Render(GLint f_iTexLocation) { //apply OpenGL settings for rendering this Object glPushAttrib(GL_TEXTURE_BIT); glEnable(GL_TEXTURE_2D); //modulate the texture color with the computed material //colors + glActiveTexture(GL_TEXTURE0); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBindTexture(GL_TEXTURE_2D, m_uiColorTex); + + + if (f_iTexLocation != 0) + { + glUniform1i(f_iTexLocation, 0); + } //set material properties glMaterialfv(GL_FRONT, GL_AMBIENT, m_Mat.m_fAmb); diff --git a/matchblox/engine/C_3DObject.h b/matchblox/engine/C_3DObject.h index 2ad5a88..c025d11 100644 --- a/matchblox/engine/C_3DObject.h +++ b/matchblox/engine/C_3DObject.h @@ -42,8 +42,8 @@ public: void TransRotateScale(); //applies the scaling, translation and rotation //for this object - virtual void Render(); //renders the object using the current projection - //and modelview matrices + virtual void Render(GLint f_iTexLocation); //renders the object using the current projection + //and modelview matrices protected: Vect3D_t m_Pos, diff --git a/matchblox/engine/C_Block.cpp b/matchblox/engine/C_Block.cpp index 81d3b66..50432ac 100644 --- a/matchblox/engine/C_Block.cpp +++ b/matchblox/engine/C_Block.cpp @@ -24,7 +24,7 @@ C_Block::~C_Block() } -void C_Block::Render(unsigned int f_iElapsedTime) +void C_Block::Render(unsigned int f_iElapsedTime, GLint f_iTexLocation) { unsigned int l_uiDeltaTime = f_iElapsedTime - m_uiAnimStart; double l_Scale, l_Scalexz, l_Frac; @@ -46,7 +46,7 @@ void C_Block::Render(unsigned int f_iElapsedTime) //glScaled(l_Scale, l_Scale, l_Scale); SetScale(l_Scale, l_Scale, l_Scale); TransRotateScale(); - C_3DObject::Render(); + C_3DObject::Render(f_iTexLocation); break; case BS_FADE_OUT: @@ -54,7 +54,7 @@ void C_Block::Render(unsigned int f_iElapsedTime) // glScaled(l_Scale, l_Scale, l_Scale); SetScale(l_Scale, l_Scale, l_Scale); TransRotateScale(); - C_3DObject::Render(); + C_3DObject::Render(f_iTexLocation); break; case BS_COLLIDE: //wobble @@ -64,14 +64,14 @@ void C_Block::Render(unsigned int f_iElapsedTime) l_Scalexz = 1.0 - sin(l_Frac)*0.2; SetScale(l_Scalexz, l_Scale, l_Scalexz); TransRotateScale(); - C_3DObject::Render(); + C_3DObject::Render(f_iTexLocation); break; case BS_IDLE: default: SetScale(1.0, 1.0, 1.0); TransRotateScale(); - C_3DObject::Render(); + C_3DObject::Render(f_iTexLocation); break; } diff --git a/matchblox/engine/C_Block.h b/matchblox/engine/C_Block.h index f42c2ba..fcc1808 100644 --- a/matchblox/engine/C_Block.h +++ b/matchblox/engine/C_Block.h @@ -21,7 +21,7 @@ public: MatProps_t f_Mat); ~C_Block(); - void Render(unsigned int f_iElapsedTime); + void Render(unsigned int f_iElapsedTime, GLint f_iTexLocation); inline void SetState(BlockAnimState f_State, unsigned int f_uiElapsedTime) { if (m_CurrState != f_State) {m_CurrState = f_State; m_uiAnimStart = f_uiElapsedTime; } } diff --git a/matchblox/engine/C_Box.cpp b/matchblox/engine/C_Box.cpp index 343ae98..573c78c 100644 --- a/matchblox/engine/C_Box.cpp +++ b/matchblox/engine/C_Box.cpp @@ -66,7 +66,7 @@ void C_Box::RandomizeTiles() } } -void C_Box::Render() +void C_Box::Render(GLint f_iTexLocation) { // glPushMatrix(); @@ -75,7 +75,7 @@ void C_Box::Render() TransRotateScale(); //render the box - C_3DObject::Render(); + C_3DObject::Render(f_iTexLocation); //render the tiles @@ -89,7 +89,7 @@ void C_Box::Render() //tile with a hole glPushMatrix(); m_pTiles[l_iTileIndex]->TransRotateScale(); - m_pTiles[l_iTileIndex]->Render(); + m_pTiles[l_iTileIndex]->Render(f_iTexLocation); glPopMatrix(); } else @@ -101,7 +101,7 @@ void C_Box::Render() m_LowLeftTilePos.z - (double)y * m_dTileSize); glPushMatrix(); m_pTiles[4]->TransRotateScale(); - m_pTiles[4]->Render(); + m_pTiles[4]->Render(f_iTexLocation); glPopMatrix(); } } diff --git a/matchblox/engine/C_Box.h b/matchblox/engine/C_Box.h index ed8c133..a517135 100644 --- a/matchblox/engine/C_Box.h +++ b/matchblox/engine/C_Box.h @@ -17,7 +17,7 @@ public: ~C_Box(); void RandomizeTiles(); - void Render(); + void Render(GLint f_iTexLocation); private: C_3DObject **m_pTiles; //the tile objects for the top face of the box (holes) diff --git a/matchblox/engine/C_Hand.cpp b/matchblox/engine/C_Hand.cpp index 796be88..785ea12 100644 --- a/matchblox/engine/C_Hand.cpp +++ b/matchblox/engine/C_Hand.cpp @@ -35,19 +35,19 @@ void C_Hand::Render(unsigned int f_iElapsedTime) { case HS_COLLIDE: m_Mat.setEmi(1.0, 0.0, 0.0, 1.0); - C_3DObject::Render(); + C_3DObject::Render(0); break; case HS_GRAB: - C_3DObject::Render(); + C_3DObject::Render(0); break; case HS_RELEASE: - C_3DObject::Render(); + C_3DObject::Render(0); break; case HS_IDLE: default: - C_3DObject::Render(); + C_3DObject::Render(0); break; } diff --git a/matchblox/engine/C_Log.h b/matchblox/engine/C_Log.h index 2b598dd..a376e76 100644 --- a/matchblox/engine/C_Log.h +++ b/matchblox/engine/C_Log.h @@ -2,6 +2,8 @@ #define C_LOG_HEADER_FILE + + class C_Log { public: @@ -13,7 +15,7 @@ public: bool LogSessionTotals(int f_iUserID, int f_iGameID, unsigned int f_uiTotalTime); private: -// FILE *m_pLogFile; + }; #endif //C_LOG_HEADER_FILE diff --git a/matchblox/engine/C_MatchBloxEngine.cpp b/matchblox/engine/C_MatchBloxEngine.cpp index 6984239..2a660fd 100644 --- a/matchblox/engine/C_MatchBloxEngine.cpp +++ b/matchblox/engine/C_MatchBloxEngine.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -21,6 +22,8 @@ #include "C_Smoother.h" #include "C_MatchBloxEngine.h" #include "font.h" +#include "stereoheadtrackfrustum.h" +#include "textfile.h" extern "C" { extern GLuint g_iBase; @@ -34,24 +37,33 @@ C_MatchBloxEngine::C_MatchBloxEngine(const char *f_strModelPath, { //create logger - - //Load models - if (LoadModels(f_strModelPath)) + + m_State = ES_INITIALISED; + //load and build the grayscale shader program + if (!LoadGrayScaleShader()) { - //set state to initialised; - m_State = ES_INITIALISED; + m_State = ES_ERROR; } - else + m_GSConvScale[0] = 0.299; //grayscale conversion scale (default 0.299, 0.587, 0.114) + m_GSConvScale[1] = 0.587; + m_GSConvScale[2] = 0.114; + + //Load models + if (!LoadModels(f_strModelPath)) { + //set state to initialised; m_State = ES_ERROR; } - + //initialise a random seed srand ( time(NULL) ); //init vars m_CurrentBox = BS_SMALL; + m_bHeadTrackingEnabled = false; + m_bStereoEnabled = false; + //init the world bounding box m_WorldBox.m_Min = Vect3D_t(-15.0, -5.0, -15.0); m_WorldBox.m_Max = Vect3D_t(15.0, 15.0, 15.0); @@ -182,11 +194,75 @@ GameResult C_MatchBloxEngine::ProcessMsgs(void) } -void C_MatchBloxEngine::Render(unsigned int f_uiElapsedTime) +void C_MatchBloxEngine::Render(unsigned int f_uiElapsedTime, input_payload_wiimote &f_HTWiimote, FrustumParms_t &f_FrustParms) { - //glMatrixMode(GL_MODELVIEW); - //glLoadIdentity(); + Vect3D_t l_LeftEye, l_CenterEye, l_RightEye; + + if (f_HTWiimote.posDataValid) + { + //calculate the eye positions + CalcEyePosInMM(&f_HTWiimote, STEREO_LEFT_EYE, f_FrustParms, l_LeftEye); + CalcEyePosInMM(&f_HTWiimote, STEREO_RIGHT_EYE, f_FrustParms, l_RightEye); + CalcEyePosInMM(&f_HTWiimote, MONO_CENTER, f_FrustParms, l_CenterEye); + } + else + { + //set default positions + l_LeftEye = l_RightEye = l_CenterEye = Vect3D_t(0.0, 0.0, f_FrustParms.m_dDefHeadDistMM); + l_LeftEye.x = f_FrustParms.m_dEyeDistMM * -0.5; + l_RightEye.x = f_FrustParms.m_dEyeDistMM * 0.5; + } + + //always render the environment map in color, using the mono head tracked frustum + SetFrustum(f_FrustParms, l_CenterEye, true); + RenderEnv(f_uiElapsedTime); + + if (!m_bStereoEnabled) + { + //render the 3d shit once + SetFrustum(f_FrustParms, l_CenterEye); + RenderMain(f_uiElapsedTime); + } + else + { + //enable grayscale shader + glUseProgram(m_GrayScaleShaderProgram); + //set the conversion scale + glUniform3fv(m_GSConvScaleLocation, 1, m_GSConvScale); + + for (int CurrentEye=0; CurrentEye<2; CurrentEye++) //STEREO_LEFT_EYE = 0, STEREO_RIGHT_EYE = 1 + { + //clear depth buffer + glClear(GL_DEPTH_BUFFER_BIT); + + //set colormask + if (CurrentEye == STEREO_LEFT_EYE) + { + glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_TRUE); + //set frustum + SetFrustum(f_FrustParms, l_LeftEye); + } + else + { + glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE); + //set frustum + SetFrustum(f_FrustParms, l_RightEye); + } + + RenderMain(f_uiElapsedTime); + } + + //restore the colormask + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + //disable greyscale shader + glUseProgram(0); + } + + RenderOverlay(f_uiElapsedTime); +} +void C_MatchBloxEngine::RenderEnv(unsigned int f_uiElapsedTime) +{ glPushMatrix(); //set camera pitch @@ -196,6 +272,11 @@ void C_MatchBloxEngine::Render(unsigned int f_uiElapsedTime) m_pEnvMap->Render(); glPopMatrix(); +} + +void C_MatchBloxEngine::RenderMain(unsigned int f_uiElapsedTime) +{ + GLint l_iTexShaderLocation = m_bStereoEnabled? m_GSTextureLocation : 0; glPushMatrix(); @@ -203,27 +284,49 @@ void C_MatchBloxEngine::Render(unsigned int f_uiElapsedTime) glTranslated(0.0, 0.0, -16.0); glRotated(20.0, 1.0, 0.0, 0.0); - m_pBox[(int)m_CurrentBox]->Render(); + //always render the box + m_pBox[(int)m_CurrentBox]->Render(l_iTexShaderLocation); switch (m_State) { + case ES_PLAYING_GRAB_BLOCK: + case ES_PLAYING_PUT_BLOCK: + m_pBlock[(int)m_CurrentBlock]->Render(f_uiElapsedTime, l_iTexShaderLocation); + m_pHand->Render(f_uiElapsedTime); //do not break also render the hand case ES_INITIALISED: case ES_ERROR: m_pHand->Render(f_uiElapsedTime); break; + } + + glPopMatrix(); +} + +void C_MatchBloxEngine::RenderOverlay(unsigned int f_uiElapsedTime) +{ + switch (m_State) + { + case ES_INITIALISED: + case ES_ERROR: + break; case ES_GET_READY: //render some GET READY text RenderGetReady(); + if (f_uiElapsedTime - m_uiLastPosValid > 5000) + { + RenderPointHere(); + } break; case ES_PLAYING_GRAB_BLOCK: case ES_PLAYING_PUT_BLOCK: - m_pBlock[(int)m_CurrentBlock]->Render(f_uiElapsedTime); - m_pHand->Render(f_uiElapsedTime); - //render timer and block count RenderHUD(f_uiElapsedTime); + if (f_uiElapsedTime - m_uiLastPosValid > 5000) + { + RenderPointHere(); + } break; case ES_PAUSED: @@ -234,14 +337,6 @@ void C_MatchBloxEngine::Render(unsigned int f_uiElapsedTime) //render results... break; } - - if (f_uiElapsedTime - m_uiLastPosValid > 5000) - { - RenderPointHere(); - } - - glPopMatrix(); - } void C_MatchBloxEngine::RenderGetReady() @@ -325,14 +420,20 @@ void C_MatchBloxEngine::RenderText(GLint x, GLint y, char *string, struct ColorS glPopAttrib(); } -bool C_MatchBloxEngine::NewGame(int f_iUserID, int f_iGameId, BoxSize f_BS) +bool C_MatchBloxEngine::NewGame(int f_iGameMode) { if(m_State == ES_INITIALISED) { - m_CurrentBox = f_BS; - + switch (f_iGameMode) + { + case 0: + m_bHeadTrackingEnabled = true; + m_bStereoEnabled = true; + m_CurrentBox = BoxSize::BS_MED; + } + //prepare a session struct for administration - m_pCurrentSession = new GameSession(m_GameSettings.m_iNrOfTurns, f_BS); + m_pCurrentSession = new GameSession(m_GameSettings.m_iNrOfTurns, m_CurrentBox); //randomize the box tiles m_pBox[(int)m_CurrentBox]->RandomizeTiles(); @@ -413,6 +514,65 @@ bool C_MatchBloxEngine::Abort() return false; } +bool C_MatchBloxEngine::LoadGrayScaleShader() +{ + GLint l_bStatus; + char *vs_text = NULL,*fs_text = NULL; + GLuint vs = glCreateShader(GL_VERTEX_SHADER), + fs = glCreateShader(GL_FRAGMENT_SHADER); + + vs_text = textFileRead("shaders\\grayscale.vert"); + if (vs_text == NULL) + { + return false; + } + fs_text = textFileRead("shaders\\grayscale.frag"); + if (fs_text == NULL) + { + free(vs_text); + return false; + } + + glShaderSource(vs, 1, (const char**)&vs_text,NULL); + glShaderSource(fs, 1, (const char**)&fs_text,NULL); + + free(vs_text); + free(fs_text); + + glCompileShader(vs); +// printShaderInfoLog(vs); + glGetShaderiv(vs, GL_COMPILE_STATUS, &l_bStatus); + if (l_bStatus == GL_FALSE) + { + return false; + } + + glCompileShader(fs); +// printShaderInfoLog(fs); + glGetShaderiv(fs, GL_COMPILE_STATUS, &l_bStatus); + if (l_bStatus == GL_FALSE) + { + return false; + } + + m_GrayScaleShaderProgram = glCreateProgram(); + glAttachShader(m_GrayScaleShaderProgram,fs); + glAttachShader(m_GrayScaleShaderProgram,vs); + + glLinkProgram(m_GrayScaleShaderProgram); +// printProgramInfoLog(g_GameState.m_GreyScaleShaderProgram); + glGetProgramiv(m_GrayScaleShaderProgram, GL_LINK_STATUS, &l_bStatus); + if (l_bStatus == GL_FALSE) + { + return false; + } + + m_GSConvScaleLocation = glGetUniformLocation(m_GrayScaleShaderProgram, "g_ConversionWeights"); + m_GSTextureLocation = glGetUniformLocation(m_GrayScaleShaderProgram, "g_TexSampler"); + + return true; +} + bool C_MatchBloxEngine::LoadModels(const char* f_strModelDir) { MatProps_t l_Mat; diff --git a/matchblox/engine/C_MatchBloxEngine.h b/matchblox/engine/C_MatchBloxEngine.h index 4e5fcf3..5d90291 100644 --- a/matchblox/engine/C_MatchBloxEngine.h +++ b/matchblox/engine/C_MatchBloxEngine.h @@ -6,7 +6,7 @@ #include "message_input.h" #include "typedefs.h" #include -#include "C_Smoother.h" +#include "C_Smoother.h" //#include using namespace std; @@ -157,9 +157,9 @@ public: ~C_MatchBloxEngine(); GameResult ProcessMsgs(void); - void Render(unsigned int f_uiElapsedTime); - - bool NewGame(int f_iUserID, int f_iGameId, BoxSize f_BS); + void Render(unsigned int f_uiElapsedTime, input_payload_wiimote &f_HTWiimote, FrustumParms_t &f_FrustParms); + + bool NewGame(int f_iGameMode); bool StartGame(); bool Pause(); bool Resume(); @@ -189,14 +189,25 @@ private: //mapped to the z=0.0 in world coordinates BoundingBox_t m_WorldBox; //an invisible box that limits the movement of the //player + bool m_bHeadTrackingEnabled, + m_bStereoEnabled; + GLuint m_GrayScaleShaderProgram; //handle to the grayscale shader program + GLint m_GSConvScaleLocation, //handle to the g_ConversionScale variable in the shader + m_GSTextureLocation; // + GLfloat m_GSConvScale[3]; //grayscale conversion scale (default 0.299, 0.587, 0.114) //init routines bool LoadModels(const char* f_strModelDir); void DeleteModels(); void LoadTexture(const char* f_BmpName, GLuint &f_uiTexHandle); + bool LoadGrayScaleShader(); //render routines + void RenderEnv(unsigned int f_uiElapsedTime); + void RenderMain(unsigned int f_uiElapsedTime); + void RenderOverlay(unsigned int f_uiElapsedTime); + void RenderGetReady(); void RenderHUD(unsigned int f_uiElapsedTime); void RenderResults(); @@ -213,8 +224,6 @@ private: void GameFinished(); //wiimote functions - //bool FindIRDots(input_payload_wiimote *f_pWiimote, ir_dot_t f_Dot[2]); - //bool CalcWiimoteRelativeCursorPos(input_payload_wiimote *f_pWiimote, Vect3D_t *f_pRelPos); bool ConvertWiimoteToWorld(input_payload_wiimote *f_pWiimote, Vect3D_t *f_WorldPos); }; diff --git a/matchblox/main.cpp b/matchblox/main.cpp index 3e54784..fb84a97 100644 --- a/matchblox/main.cpp +++ b/matchblox/main.cpp @@ -65,63 +65,6 @@ bool InitWiiMotes() } } -bool LoadGreyScaleShader() -{ - GLint l_bStatus; - char *vs_text = NULL,*fs_text = NULL; - GLuint vs = glCreateShader(GL_VERTEX_SHADER), - fs = glCreateShader(GL_FRAGMENT_SHADER); - - vs_text = textFileRead("shaders\\greyscale.vert"); - if (vs_text == NULL) - { - return false; - } - fs_text = textFileRead("shaders\\greyscale.frag"); - if (fs_text == NULL) - { - free(vs_text); - return false; - } - - glShaderSource(vs, 1, (const char**)&vs_text,NULL); - glShaderSource(fs, 1, (const char**)&fs_text,NULL); - - free(vs_text); - free(fs_text); - - glCompileShader(vs); -// printShaderInfoLog(vs); - glGetShaderiv(vs, GL_COMPILE_STATUS, &l_bStatus); - if (l_bStatus == GL_FALSE) - { - return false; - } - - glCompileShader(fs); -// printShaderInfoLog(fs); - glGetShaderiv(fs, GL_COMPILE_STATUS, &l_bStatus); - if (l_bStatus == GL_FALSE) - { - return false; - } - - g_GameState.m_GreyScaleShaderProgram = glCreateProgram(); - glAttachShader(g_GameState.m_GreyScaleShaderProgram,fs); - glAttachShader(g_GameState.m_GreyScaleShaderProgram,vs); - - glLinkProgram(g_GameState.m_GreyScaleShaderProgram); -// printProgramInfoLog(g_GameState.m_GreyScaleShaderProgram); - glGetProgramiv(g_GameState.m_GreyScaleShaderProgram, GL_LINK_STATUS, &l_bStatus); - if (l_bStatus == GL_FALSE) - { - return false; - } - - g_GameState.m_GSConvScaleLoc = glGetUniformLocation(g_GameState.m_GreyScaleShaderProgram, "g_ConversionWeights"); - - return true; -} void init_gl(void) { @@ -144,7 +87,8 @@ void idle_func(void) struct input_payload_wiimote wiimote_payload; struct messageq_s message; - g_GameState.m_pWiimote[0]->FillWiimoteMsgPayload(wiimote_payload, 205.0); // << should be a sensor bar led distance + wiimote_payload.posDataValid = false; + //g_GameState.m_pWiimote[0]->FillWiimoteMsgPayload(wiimote_payload, 205.0); // << should be a sensor bar led distance message.recipient = MESSAGE_MENU | MESSAGE_RENDERER; message.sender = MESSAGE_INPUT_WIIMOTE; @@ -164,14 +108,19 @@ void render_scene(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - g_pEngine->Render(glutGet(GLUT_ELAPSED_TIME)); + input_payload_wiimote l_HTWiimote; + l_HTWiimote.posDataValid = false; + + //g_GameState.m_pWiimote[0]->FillWiimoteMsgPayload(l_HTWiimote, 210.0); + g_pEngine->Render(glutGet(GLUT_ELAPSED_TIME), l_HTWiimote, g_GameState.m_FrustumParms); + //render the menu glDisable(GL_LIGHTING); glPushMatrix(); MenuRender(); glPopMatrix(); glEnable(GL_LIGHTING); - + glutSwapBuffers(); } // render_scene @@ -201,16 +150,6 @@ void process_normal_keys(unsigned char key, int x, int y) case KEY_ESCAPE: exit(0); break; - case 'n': - g_pEngine->Abort(); - g_pEngine->NewGame(0, 0, BS_SMALL); - break; - case 'p': - if (!g_pEngine->Pause()) - { - g_pEngine->Resume(); - } - break; } payload.specialkey = FALSE; @@ -261,7 +200,7 @@ int main(int argc, char **argv) glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); - glutInitWindowSize(SCREEN_WIDTH, SCREEN_HEIGHT); + //glutInitWindowSize(SCREEN_WIDTH, SCREEN_HEIGHT); glutCreateWindow("MatchBlox"); glutReshapeFunc(reshape); @@ -274,8 +213,41 @@ int main(int argc, char **argv) glutSetCursor(GLUT_CURSOR_NONE); init_gl(); + + //init the GL Extension Wrangler library + glewInit(); + + //check for OpenGL 2.0 support + if (!glewIsSupported("GL_VERSION_2_0")) + { + printf("Your graphics hardware/software does not support OpenGL 2.0\n"); + exit(1); + } + MenuInit(SCREEN_WIDTH, SCREEN_HEIGHT); - InitWiiMotes(); + //InitWiiMotes(); + + // initialise the stereo vision parameters << should be loaded from a textfile + g_GameState.m_FrustumParms.m_dEyeDistMM = 70.0; //7 cm + g_GameState.m_FrustumParms.m_dDefHeadDistMM = 1000.0; //100 cm + g_GameState.m_FrustumParms.m_dHeadTrackLedDist = 205.0; + g_GameState.m_FrustumParms.m_dRadPerCameraPixel = (41.0*(M_PI/180.0))/1016.0; + g_GameState.m_FrustumParms.m_dCameraXCenter = 1016.0/2.0; + g_GameState.m_FrustumParms.m_dCameraYCenter = 760.0/2.0; + g_GameState.m_FrustumParms.m_dYAngleCorrection = 0.0; //to be initialised correctly + g_GameState.m_FrustumParms.m_dScreenHeightWorld = 20.0; + g_GameState.m_FrustumParms.m_dCameraYOffset = 130.0; + g_GameState.m_FrustumParms.m_dScreenHeightMM = 2100.0; + g_GameState.m_FrustumParms.m_dScreenAspect = 4.0/3.0; + g_GameState.m_GSConvScale[0] = 0.299; + g_GameState.m_GSConvScale[1] = 0.587; + g_GameState.m_GSConvScale[2] = 0.114; + /*g_GameState.m_FrustumParms.m_dCameraYOffset = 205.0; + g_GameState.m_FrustumParms.m_dScreenHeightMM = 320.0; + g_GameState.m_FrustumParms.m_dScreenAspect = 16.0/10.0;*/ + + g_GameState.m_bHeadTrackingEnabled = false; + g_GameState.m_bStereoEnabled = false; GameSettings l_set = {10, 1.1, 2}; g_pEngine = new C_MatchBloxEngine("models", "", l_set); diff --git a/matchblox/matchblox.vcproj b/matchblox/matchblox.vcproj index 93a93c5..db02e39 100644 --- a/matchblox/matchblox.vcproj +++ b/matchblox/matchblox.vcproj @@ -236,6 +236,10 @@ > + + @@ -310,6 +314,10 @@ > + + -- cgit v0.12