void SetOrtho(const THVector2& minp,const THVector2& maxp) { gameMinBound=minp; gameMaxBound=maxp; gameScale=(maxp-minp) / windowSize; THOrthoMatrix33(THProjectMatrix,minp,maxp); glUniform3fv(THDefaultProgram.projectMatrixHandler,2,THProjectMatrix); const GLfloat fv[]=MAKE_VERTEX(minp.x,minp.y,maxp.x,maxp.y); memcpy(THGameFullVertices,fv,sizeof(GLfloat)*8); THLog("Set Ortho : %.1f , %.1f / %.1f , %.1f",minp.x,minp.y,maxp.x,maxp.y); }
void THGLInit() { //glClearColor(0.7f,0.6f,0.5f,1.0f); glClearColor(0.0f,0.0f,0.0f,1.0f); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); TH_GLERROR_CHECK() #if USE_DEPTH_BUFFER==1 glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glDepthMask(GL_TRUE); #else glDisable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); #endif glViewport(0, 0, windowWidthi,windowHeighti); TH_GLERROR_CHECK() const GLfloat verts[]=MAKE_VERTEX(0.0f,0.0f,1.0f,1.0f); THZeroVertices.Load((void*)verts,sizeof(GLfloat)*8,GL_STATIC_DRAW); TH_GLERROR_CHECK() THDefaultProgram.Load(); THDefaultProgram.SetColorAdd(0.0f,0.0f,0.0f,0.0f); THDefaultProgram.SetColorMultiply(1.0f,1.0f,1.0f,1.0f); TH_GLERROR_CHECK() OnSurfaceCreated(); #ifndef NDEBUG if(gameScale.x==0.0f) { THError("GameSize Not Set! Must be set in OnSurfaceCreated()"); assert(0); } #endif TH_GLERROR_CHECK() }
void ProgressCircle::OnDraw() { ImageBox::OnDraw(); float progress = hclamp(this->progress, 0.0f, 1.0f); april::Color color = this->_getDrawColor(); color.a = (unsigned char)(color.a * this->_getDisabledAlphaFactor()); if (this->progressImage != NULL) { grect rect = this->_getDrawRect(); if (progress == 1.0f) { this->progressImage->draw(rect, color); } else if (progress > 0.0f) { gvec2 p0; gvec2 p1; gvec2 splitCenter; gvec2 topLeft; gvec2 topRight; gvec2 bottomLeft; gvec2 bottomRight; switch (this->direction) { case Clockwise: splitCenter.set(1.0f, 0.5f); topLeft.set(0.0f, 1.0f); topRight.set(1.0f, 1.0f); bottomLeft.set(0.0f, 0.0f); bottomRight.set(1.0f, 0.0f); break; case Clockwise90: splitCenter.set(0.5f, 0.0f); topLeft.set(1.0f, 1.0f); topRight.set(1.0f, 0.0f); bottomLeft.set(0.0f, 1.0f); bottomRight.set(0.0f, 0.0f); break; case Clockwise180: splitCenter.set(0.0f, 0.5f); topLeft.set(1.0f, 0.0f); topRight.set(0.0f, 0.0f); bottomLeft.set(1.0f, 1.0f); bottomRight.set(0.0f, 1.0f); break; case Clockwise270: splitCenter.set(0.5f, 1.0f); topLeft.set(0.0f, 0.0f); topRight.set(0.0f, 1.0f); bottomLeft.set(1.0f, 0.0f); bottomRight.set(1.0f, 1.0f); break; case Counterclockwise: splitCenter.set(1.0f, 0.5f); topLeft.set(0.0f, 0.0f); topRight.set(1.0f, 0.0f); bottomLeft.set(0.0f, 1.0f); bottomRight.set(1.0f, 1.0f); break; case Counterclockwise90: splitCenter.set(0.5f, 0.0f); topLeft.set(0.0f, 1.0f); topRight.set(0.0f, 0.0f); bottomLeft.set(1.0f, 1.0f); bottomRight.set(1.0f, 0.0f); break; case Counterclockwise180: splitCenter.set(0.0f, 0.5f); topLeft.set(1.0f, 1.0f); topRight.set(0.0f, 1.0f); bottomLeft.set(1.0f, 0.0f); bottomRight.set(0.0f, 0.0f); break; case Counterclockwise270: splitCenter.set(0.5f, 1.0f); topLeft.set(1.0f, 0.0f); topRight.set(1.0f, 1.0f); bottomLeft.set(0.0f, 0.0f); bottomRight.set(0.0f, 1.0f); break; } harray<april::TexturedVertex> vertices; vertices += MAKE_VERTEX(gvec2(0.5f, 0.5f)); vertices += MAKE_VERTEX(splitCenter); april::TexturedVertex vertex; p0 = bottomRight; p1 = topRight; if (progress > 0.125f) { vertex = MAKE_VERTEX(topRight); vertices += vertex; vertices += vertices.first(); vertices += vertex; p0 = topRight; p1 = topLeft; } if (progress > 0.375f) { vertex = MAKE_VERTEX(topLeft); vertices += vertex; vertices += vertices.first(); vertices += vertex; p0 = topLeft; p1 = bottomLeft; } if (progress > 0.625f) { vertex = MAKE_VERTEX(bottomLeft); vertices += vertex; vertices += vertices.first(); vertices += vertex; p0 = bottomLeft; p1 = bottomRight; } if (progress > 0.875f) { vertex = MAKE_VERTEX(bottomRight); vertices += vertex; vertices += vertices.first(); vertices += vertex; p0 = bottomRight; p1 = topRight; } double angle = hmodf(progress * 360.0f + 45.0f, 90.0f) - 45.0f; // angle will always be between -45° and 45° so there is no risk here float ratio = (float)dtan(angle) * 0.5f + 0.5f; p0 += (p1 - p0) * ratio; vertices += MAKE_VERTEX(p0); this->progressImage->draw(vertices, color); } } if (this->maskImage != NULL) { this->maskImage->draw(this->_getDrawRect(), color); } }