void setupBoard(TBlock *board, const vector<TPos> *positions, TPos &p1, TPos &p2){ if (positions == NULL){ // createNewBoard(board, rand() % 20 + 5); createNewBoard(board, rand() % 20 + 15); board[0] = board[BOARD_SIZE - 1] = BLOCK_OBSTACLE; while (true) { int i = rand() % 121; if (board[i] == BLOCK_EMPTY){ board[i] = BLOCK_PLAYER_1; p1 = TPos(i); break; } } while (true){ int i = rand() % 121; if (board[i] == BLOCK_EMPTY){ board[i] = BLOCK_PLAYER_2; p2 = TPos(i); break; } } } else { memset(board, 0, BOARD_SIZE*sizeof(TBlock)); for (int j = 0; j < (int)positions->size(); j++){ SET_BLOCK(board, positions->at(j), BLOCK_OBSTACLE); } SET_BLOCK(board, p1, BLOCK_PLAYER_1); SET_BLOCK(board, p2, BLOCK_PLAYER_2); } }
// -------------------------------------------------------------------------------- // Name : AddRect // Description : Add the given rect and updates anchor points // -------------------------------------------------------------------------------- void CRectPlacement::AddRect (const TRect &r) { m_vRects.push_back(r); m_area += r.w*r.h; // Add two new anchor points AddPosition(TPos(r.x, r.y+r.h+m_margin)); AddPosition(TPos(r.x+r.w+m_margin, r.y)); }
// -------------------------------------------------------------------------------- // Name : // Description : // -------------------------------------------------------------------------------- void CRectPlacement::Init (int w, int h) { End(); m_size = TRect(0, 0, w, h); m_vPositions.push_back(TPos(m_margin, m_margin)); m_area = 0; }
void createBoardWithOutIsland(TBlock *board, TPos p1 = 0i16, TPos p2 = 120i16){ memset(board, 0, BOARD_SIZE*sizeof(TBlock)); int nObject = rand() % 30 + 30; vector<TPos> obstacles = { 60 }; for (int i = 0; i < 121; i++){ SET_BLOCK(board, TPos(i), BLOCK_OBSTACLE); } SET_BLOCK(board, TPos(60), BLOCK_EMPTY); for (int i = 1; i < nObject;){ TPos t = TPos(obstacles[rand() % obstacles.size()]); TPos newT = MOVE(t, rand() % 4 + 1); if (GET_BLOCK(board, newT) == BLOCK_OBSTACLE){ SET_BLOCK(board, newT, BLOCK_EMPTY); obstacles.push_back(newT); i++; } } p1 = obstacles[rand() % obstacles.size()]; SET_BLOCK(board, p1, BLOCK_PLAYER_1); }
/** * \brief drawText, render 2D text on the screen (Orthogonal Projection) * @param str, text string. * @param pos, 2D position on screen, * @param rgba, text color * @param tick time elapsed * @return float width of text string. */ float RenderText::drawText(const char*str, glm::vec3 &pos, glm::vec4 &rgba, float tick) { // checkGLError("RenderText::DrawText Should be ok!"); float width = 0; mOPos = glm::vec3(0.0f,0.0f,0.0f); mOPos = pos; int num = strlen(str); glm::vec4 *vertices = 0; glDisable(GL_DEPTH_TEST); glm::mat4 m = glm::ortho(0.0f, static_cast<float>(mWidth),static_cast<float>(mHeight),0.0f,-200.0f,1000.0f); // Use the font class to build the vertex array from the sentence text and sentence draw location. // Create the vertex array. mScaleY = -mScaleY; vertices = getVertices(str, false, &width); // note uses m_pos creates or retrieves existing vertex buffer from a cache table mScaleY = -mScaleY; TextShader &shader= mTextShader; glEnable (GL_BLEND); mBlendType = BL_ADDITIVE; switch (mBlendType) { case BL_ADDITIVE: // Additive glBlendFunc(GL_ONE, GL_ONE); // glBlendFunc( GL_DST_ALPHA, GL_ONE_MINUS_SRC_COLOR ); // very good additive break; case BL_TRANSLUCENT: // Requires alpha glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR); // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Texture uses alpha break; case BL_SUBTRACTIVE: //glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR); glBlendFunc( GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA ); //subtractive black => max // glBlendFunc(GL_ZERO, GL_SRC_ALPHA); // needs alpha // glBlendFunc(GL_ZERO, GL_SRC_COLOR); break; case BL_TRANSPARENT: glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR); break; } // Use the program object glUseProgram(shader.mShader); checkGLError("RenderText::DrawText glUseProgram (Text)"); // 1. create buffers tri array for simplicity? so that every tri can be handled separately or with a new index buffer could be expensive though??? // Load the vertex data glVertexAttribPointer(shader.mAttribVtxLoc, 4, GL_FLOAT, GL_FALSE, sizeof(float)*4, &vertices[0].x); checkGLError("RenderText::DrawText glVertexAttribPointer (V)"); glEnableVertexAttribArray(shader.mAttribVtxLoc); checkGLError("RenderText::DrawText glEnableVertexAttribArray (V)"); glActiveTexture(GL_TEXTURE0 + 0); checkGLError("RenderText::DrawText glActiveTexture"); glBindTexture(GL_TEXTURE_2D, mFont->GetTexture(0)); checkGLError("glBindTexture"); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); checkGLError("glTexParameteri"); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); checkGLError("glTexParameteri"); glUniform1i(shader.mTexture, 0 ); // Texture Unit 0 checkGLError("RenderText::DrawText glUniform1i"); // Once per frame glUniform1f(shader.mTimeLoc, tick); checkGLError("RenderText::DrawText glUniform1f"); glUniform2f(shader.mResolutionLoc, 1.0f/(float)mWidth, 1.0f/(float)mHeight); checkGLError("RenderText::DrawText glUniform2f"); glUniformMatrix4fv(shader.mMatrixPVW, 1, GL_FALSE, &m[0][0]); checkGLError("RenderText::DrawText glUniformMatrix4fv"); glm::vec3 sv(1.0f, 1.0f, 1.0f); glUniform3fv(shader.mScaleV,1, (float *)&sv.x); // mScale location => variable "ScaleV" in vertex shader checkGLError("RenderText::DrawText glUniformMatrix3fv"); glm::vec4 color = rgba; glUniform4fv(shader.mColor,1, (float *)&color.x); checkGLError("RenderText::DrawText glUniformMatrix4fv"); glm::vec4 TPos(mPos.x,mPos.y,mPos.z, 1.0f); glUniform4fv(shader.mTPos, 1, (float *)&TPos.x); checkGLError("RenderText::DrawText glUniformMatrix4fv"); glDrawArrays(GL_TRIANGLES, 0, 6*num); checkGLError("RenderText::DrawText glDrawArrays"); // Clean-up glDisableVertexAttribArray(shader.mAttribVtxLoc); checkGLError("RenderText::DrawText glDisableVertexAttribArray (Vtx)"); glBindTexture(GL_TEXTURE_2D, 0); glUseProgram(0); checkGLError("RenderText::DrawText glUseProgram(0)"); releaseVertices(vertices, false); glDisable(GL_BLEND); return width; // Generate a buffer for the vertices }