void StGLMenuProgram::use(StGLContext& theCtx, const StGLVec4& theColor, const GLfloat theOpacityValue, const GLfloat theDispX) { StGLProgram::use(theCtx); theCtx.core20fwd->glUniform4fv(uniColorLoc, 1, StGLVec4(theColor.rgb(), theColor.a() * theOpacityValue)); if(!stAreEqual(myDispX, theDispX, 0.0001f)) { myDispX = theDispX; theCtx.core20fwd->glUniform4fv(uniDispLoc, 1, StGLVec4(theDispX, 0.0f, 0.0f, 0.0f)); } }
void StGLMenu::stglDraw(unsigned int theView) { if(!myIsInitialized || !isVisible()) { return; } if(myIsResized) { stglResize(); } StGLContext& aCtx = getContext(); aCtx.core20fwd->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); aCtx.core20fwd->glEnable(GL_BLEND); StGLMenuProgram& aProgram = myRoot->getMenuProgram(); if(myVertexBndBuf.isValid()) { aProgram.use(aCtx, StGLVec4(0.0f, 0.0f, 0.0f, 1.0f), myOpacity, myRoot->getScreenDispX()); myVertexBndBuf.bindVertexAttrib (aCtx, aProgram.getVVertexLoc()); aCtx.core20fwd->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); myVertexBndBuf.unBindVertexAttrib(aCtx, aProgram.getVVertexLoc()); } aProgram.use(aCtx, myColorVec, myOpacity, myRoot->getScreenDispX()); myVertexBuf.bindVertexAttrib (aCtx, aProgram.getVVertexLoc()); aCtx.core20fwd->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); myVertexBuf.unBindVertexAttrib(aCtx, aProgram.getVVertexLoc()); aProgram.unuse(aCtx); aCtx.core20fwd->glDisable(GL_BLEND); StGLWidget::stglDraw(theView); }
void StGLMenuProgram::use(StGLContext& theCtx, const GLfloat theDispX) { StGLProgram::use(theCtx); if(!stAreEqual(myDispX, theDispX, 0.0001f)) { myDispX = theDispX; theCtx.core20fwd->glUniform4fv(uniDispLoc, 1, StGLVec4(theDispX, 0.0f, 0.0f, 0.0f)); } }
StGLRootWidget::StGLRootWidget(const StHandle<StResourceManager>& theResMgr) : StGLWidget(NULL, 0, 0, StGLCorner(ST_VCORNER_TOP, ST_HCORNER_LEFT)), myShareArray(new StGLSharePointer*[10]), myShareSize(10), myResMgr(theResMgr), myScrDispX(0.0f), myLensDist(0.0f), myScrDispXPx(0), myMenuProgram(new StGLMenuProgram()), myTextProgram(new StGLTextProgram()), myTextBorderProgram(new StGLTextBorderProgram()), myIsMobile(false), myScaleGlX(1.0), myScaleGlY(1.0), myScaleGUI(1.0f), myResolution(72), cursorZo(0.0, 0.0), myFocusWidget(NULL), myIsMenuPressed(false), myMenuIconSize(IconSize_16), myClickThreshold(3) { // unify access StGLWidget::myRoot = this; myViewport[0] = 0; myViewport[1] = 0; myViewport[2] = 1; myViewport[3] = 1; // allocate shared resources array for(size_t aResId = 0; aResId < myShareSize; ++aResId) { myShareArray[aResId] = new StGLSharePointer(); } myGlFontMgr = new StGLFontManager(myResolution); myColors[Color_Menu] = StGLVec4(0.855f, 0.855f, 0.855f, 1.0f); myColors[Color_MenuHighlighted] = StGLVec4(0.765f, 0.765f, 0.765f, 1.0f); myColors[Color_MenuClicked] = StGLVec4(0.500f, 0.500f, 0.500f, 1.0f); myColors[Color_MenuText] = StGLVec4(0.000f, 0.000f, 0.000f, 1.0f); myColors[Color_MenuIcon] = StGLVec4(0.000f, 0.000f, 0.000f, 0.8f); myColors[Color_MessageBox] = StGLVec4(0.060f, 0.060f, 0.060f, 1.0f); myColors[Color_MessageText] = StGLVec4(1.000f, 1.000f, 1.000f, 1.0f); myColors[Color_ScrollBar] = StGLVec4(0.765f, 0.765f, 0.765f, 0.8f); myColors[Color_IconActive] = StGLVec4(1.000f, 1.000f, 1.000f, 1.0f); setupTextures(); }
void StGeometryTest::resizeBrightness() { static const size_t BR_QUADS = 11; static const size_t VERT_PER_QUAD = 6; StGLContext& aCtx = getContext(); StGLVec2 rectSize(myCellSize.x(), 2.0f * myCellSize.y()); // move to the center StGLVec2 bottomLeft(-1.0f + 0.5f * (2.0f - GLfloat(BR_QUADS) * rectSize.x()), -1.0f + rectSize.y()); GLfloat anYBottom = bottomLeft.y() + 4.0f * myPixelSize.x(); GLfloat anYTop = bottomLeft.y() + rectSize.y() - 4.0f * myPixelSize.x(); // setup vertices StArray<StGLVec4> aVertArray(BR_QUADS * VERT_PER_QUAD); for(size_t quadId = 0; quadId < BR_QUADS; ++quadId) { GLfloat anXLeft = bottomLeft.x() + GLfloat(quadId + 0) * rectSize.x() + 4.0f * myPixelSize.x(); GLfloat anXRight = bottomLeft.x() + GLfloat(quadId + 1) * rectSize.x() - 4.0f * myPixelSize.x(); aVertArray[quadId * VERT_PER_QUAD + 0] = StGLVec4(anXLeft, anYBottom, 0.0f, 1.0f); aVertArray[quadId * VERT_PER_QUAD + 1] = StGLVec4(anXRight, anYBottom, 0.0f, 1.0f); aVertArray[quadId * VERT_PER_QUAD + 2] = StGLVec4(anXRight, anYTop, 0.0f, 1.0f); aVertArray[quadId * VERT_PER_QUAD + 3] = StGLVec4(anXRight, anYTop, 0.0f, 1.0f); aVertArray[quadId * VERT_PER_QUAD + 4] = StGLVec4(anXLeft, anYBottom, 0.0f, 1.0f); aVertArray[quadId * VERT_PER_QUAD + 5] = StGLVec4(anXLeft, anYTop, 0.0f, 1.0f); } myBrightness.changeVBO(ST_VBO_VERTEX)->init(aCtx, aVertArray); // setup color (increased brightness): 3% 10% 20% 30% ... 100% StArray<StGLVec4> aColorsArray(BR_QUADS * VERT_PER_QUAD); StGLVec4 aColor(0.03f, 0.03f, 0.03f, 1.0f); StGLVec4 aColorDelta(0.1f, 0.1f, 0.1f, 1.0f); for(size_t quadId = 0; quadId < BR_QUADS; ++quadId) { setValues(aColorsArray, aColor, quadId * VERT_PER_QUAD, VERT_PER_QUAD); if(quadId == 0) { aColor = aColorDelta; } else { aColor += aColorDelta; } } myBrightness.changeVBO(ST_VBO_COLORS)->init(aCtx, aColorsArray); }
bool StGLStereoFrameBuffer::init(StGLContext& theCtx, const GLsizei theTextureSizeX, const GLsizei theTextureSizeY, const bool theNeedDepthBuffer) { // release current objects release(theCtx); if(theCtx.arbFbo == NULL) { return false; } // create the textures if(!StGLStereoTexture::initTrash(theCtx, theTextureSizeX, theTextureSizeY)) { release(theCtx); return false; } const GLuint aFboBakDraw = theCtx.stglFramebufferDraw(); const GLuint aFboBakRead = theCtx.stglFramebufferRead(); theCtx.stglBindFramebuffer(StGLFrameBuffer::NO_FRAMEBUFFER); const GLint aDepthFormat = theCtx.isGlGreaterEqual(3, 0) ? GL_DEPTH24_STENCIL8 : GL_DEPTH_COMPONENT16; if(theNeedDepthBuffer) { theCtx.arbFbo->glGenRenderbuffers(2, myGLDepthRBIds); theCtx.arbFbo->glBindRenderbuffer(GL_RENDERBUFFER, myGLDepthRBIds[StGLStereoTexture::LEFT_TEXTURE]); theCtx.arbFbo->glRenderbufferStorage(GL_RENDERBUFFER, aDepthFormat, theTextureSizeX, theTextureSizeY); } // build FBOs theCtx.arbFbo->glGenFramebuffers(2, myGLFBufferIds); theCtx.stglBindFramebuffer(myGLFBufferIds[StGLStereoTexture::LEFT_TEXTURE]); // bind left texture to left FBO as color buffer theCtx.arbFbo->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, StGLStereoTexture::myTextures[StGLStereoTexture::LEFT_TEXTURE].getTextureId(), 0); if(theNeedDepthBuffer) { // bind left render buffer to left FBO as depth buffer theCtx.arbFbo->glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, myGLDepthRBIds[StGLStereoTexture::LEFT_TEXTURE]); } bool isOk = theCtx.arbFbo->glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE; theCtx.arbFbo->glBindRenderbuffer(GL_RENDERBUFFER, StGLFrameBuffer::NO_RENDERBUFFER); if(!isOk) { release(theCtx); theCtx.stglBindFramebufferDraw(aFboBakDraw); theCtx.stglBindFramebufferRead(aFboBakRead); return false; } theCtx.stglBindFramebuffer(StGLFrameBuffer::NO_FRAMEBUFFER); if(theNeedDepthBuffer) { // create right RenderBuffer (will be used as depth buffer) theCtx.arbFbo->glBindRenderbuffer(GL_RENDERBUFFER, myGLDepthRBIds[StGLStereoTexture::RIGHT_TEXTURE]); theCtx.arbFbo->glRenderbufferStorage(GL_RENDERBUFFER, aDepthFormat, theTextureSizeX, theTextureSizeY); } theCtx.stglBindFramebuffer(myGLFBufferIds[StGLStereoTexture::RIGHT_TEXTURE]); // bind right texture to rights FBO as color buffer theCtx.arbFbo->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, StGLStereoTexture::myTextures[StGLStereoTexture::RIGHT_TEXTURE].getTextureId(), 0); if(theNeedDepthBuffer) { // bind right render buffer to right FBO as depth buffer theCtx.arbFbo->glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, myGLDepthRBIds[StGLStereoTexture::RIGHT_TEXTURE]); } isOk = theCtx.arbFbo->glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE; theCtx.arbFbo->glBindRenderbuffer(GL_RENDERBUFFER, StGLFrameBuffer::NO_RENDERBUFFER); theCtx.stglBindFramebufferDraw(aFboBakDraw); theCtx.stglBindFramebufferRead(aFboBakRead); if(!isOk) { release(theCtx); return false; } ST_DEBUG_LOG("OpenGL, created StFrameBuffer(WxH= " + getSizeX() + 'x' + getSizeY() + ')'); // create vertices buffers to draw simple textured quad StArray<StGLVec4> aQuad(4); aQuad[0] = StGLVec4( 1.0f, -1.0f, 0.0f, 1.0f); // top-right aQuad[1] = StGLVec4( 1.0f, 1.0f, 0.0f, 1.0f); // bottom-right aQuad[2] = StGLVec4(-1.0f, -1.0f, 0.0f, 1.0f); // top-left aQuad[3] = StGLVec4(-1.0f, 1.0f, 0.0f, 1.0f); // bottom-left myVerticesBuf.init(theCtx, aQuad); StArray<StGLVec2> aQuadTC(4); aQuadTC[0] = StGLVec2(1.0f, 0.0f); aQuadTC[1] = StGLVec2(1.0f, 1.0f); aQuadTC[2] = StGLVec2(0.0f, 0.0f); aQuadTC[3] = StGLVec2(0.0f, 1.0f); myTexCoordBuf.init(theCtx, aQuadTC); myViewPortX = theTextureSizeX; myViewPortY = theTextureSizeY; return true; }
void StGLMenuProgram::setColor(StGLContext& theCtx, const StGLVec4& theColor, const GLfloat theOpacityValue) { theCtx.core20fwd->glUniform4fv(uniColorLoc, 1, StGLVec4(theColor.rgb(), theColor.a() * theOpacityValue)); }
void StGeometryTest::resizeGrid(const StRectI_t& winRectPx) { StGLContext& aCtx = getContext(); // grid size_t linesCountV = 16 + 1; size_t cellSizePx = 10; size_t linesCountH = 16 + 1; if(winRectPx.width() > winRectPx.height()) { cellSizePx = winRectPx.width() / (linesCountV - 1); linesCountH = (winRectPx.height() / cellSizePx) + 1; } else { cellSizePx = winRectPx.height() / (linesCountH - 1); linesCountV = (winRectPx.width() / cellSizePx) + 1; } myCellSize.x() = 2.0f * GLfloat(cellSizePx) / GLfloat(winRectPx.width()); myCellSize.y() = 2.0f * GLfloat(cellSizePx) / GLfloat(winRectPx.height()); size_t vertixesCount = (linesCountH + linesCountV) * 2; StArray<StGLVec4> vertArray(vertixesCount); // insert black gap to make quads StGLVec2 blackGap(GLfloat(winRectPx.width() - cellSizePx * (linesCountV - 1)) / GLfloat(winRectPx.width()), GLfloat(winRectPx.height() - cellSizePx * (linesCountH - 1)) / GLfloat(winRectPx.height())); StGLVec2 bottomLeft = StGLVec2(-1.0f) + blackGap; StGLVec2 fat = StGLVec2( 2.0f) - blackGap * 2.0f; // horizontal lines for(size_t lineId = 0; lineId < linesCountH; ++lineId) { GLfloat anY = bottomLeft.y() + fat.y() * (GLfloat(lineId) / GLfloat(linesCountH - 1)); vertArray[2 * lineId] = StGLVec4(-1.0f, anY, 0.0f, 1.0f); vertArray[2 * lineId + 1] = StGLVec4( 1.0f, anY, 0.0f, 1.0f); } // vertical lines for(size_t lineId = 0; lineId < linesCountV; ++lineId) { GLfloat anX = bottomLeft.x() + fat.x() * (GLfloat(lineId) / GLfloat(linesCountV - 1)); vertArray[2 * linesCountH + 2 * lineId] = StGLVec4(anX, -1.0f, 0.0f, 1.0f); vertArray[2 * linesCountH + 2 * lineId + 1] = StGLVec4(anX, 1.0f, 0.0f, 1.0f); } myGrid.changeVBO(ST_VBO_VERTEX)->init(aCtx, vertArray); // white color StArray<StGLVec4> lColorsArray(vertixesCount, StGLVec4(1.0f)); myGrid.changeVBO(ST_VBO_COLORS)->init(aCtx, lColorsArray); // bottom left circle myCircles[0].create(StGLVec3(bottomLeft + myCellSize), myCellSize.x(), myCellSize.y(), 64); // bottom right circle myCircles[1].create(StGLVec3(bottomLeft + myCellSize * StGLVec2(GLfloat(linesCountV - 2), 1.0f)), myCellSize.x(), myCellSize.y(), 64); // top left circle myCircles[2].create(StGLVec3(bottomLeft + myCellSize * StGLVec2(1.0f, GLfloat(linesCountH - 2))), myCellSize.x(), myCellSize.y(), 64); // top right circle myCircles[3].create(StGLVec3(bottomLeft + myCellSize * StGLVec2(GLfloat(linesCountV - 2), GLfloat(linesCountH - 2))), myCellSize.x(), myCellSize.y(), 64); // center circle GLfloat minSize = 0.5f * (((linesCountV < linesCountH) ? linesCountV : linesCountH) - 1); myCircles[4].create(StGLVec3(0.0f), myCellSize.x() * minSize, myCellSize.y() * minSize, 64); // white color for(size_t aCircleId = 0; aCircleId < 5; ++aCircleId) { myCircles[aCircleId].computeMesh(); myCircles[aCircleId].initColorsArray(StGLVec4(1.0f)); myCircles[aCircleId].initVBOs(aCtx); } }
void StGeometryTest::resizeColor() { static const size_t COLOR_QUADS = 8; static const size_t VERT_PER_QUAD = 6; StGLContext& aCtx = getContext(); StGLVec2 rectSize(myCellSize.x(), 2.0f * myCellSize.y()); // move to the center StGLVec2 bottomLeft(-1.0f + 0.5f * (2.0f - GLfloat(COLOR_QUADS) * rectSize.x()), -1.0f + 2.0f * rectSize.y()); GLfloat anYBottom = bottomLeft.y() + 4.0f * myPixelSize.x(); GLfloat anYTop = bottomLeft.y() + rectSize.y() - 4.0f * myPixelSize.x(); // setup vertices StArray<StGLVec4> aVertArray(COLOR_QUADS * VERT_PER_QUAD); for(size_t quadId = 0; quadId < COLOR_QUADS; ++quadId) { GLfloat anXLeft = bottomLeft.x() + GLfloat(quadId + 0) * rectSize.x() + 4.0f * myPixelSize.x(); GLfloat anXRight = bottomLeft.x() + GLfloat(quadId + 1) * rectSize.x() - 4.0f * myPixelSize.x(); aVertArray[quadId * VERT_PER_QUAD + 0] = StGLVec4(anXLeft, anYBottom, 0.0f, 1.0f); aVertArray[quadId * VERT_PER_QUAD + 1] = StGLVec4(anXRight, anYBottom, 0.0f, 1.0f); aVertArray[quadId * VERT_PER_QUAD + 2] = StGLVec4(anXRight, anYTop, 0.0f, 1.0f); aVertArray[quadId * VERT_PER_QUAD + 3] = StGLVec4(anXRight, anYTop, 0.0f, 1.0f); aVertArray[quadId * VERT_PER_QUAD + 4] = StGLVec4(anXLeft, anYBottom, 0.0f, 1.0f); aVertArray[quadId * VERT_PER_QUAD + 5] = StGLVec4(anXLeft, anYTop, 0.0f, 1.0f); } myColors.changeVBO(ST_VBO_VERTEX)->init(aCtx, aVertArray); // setup color StArray<StGLVec4> aColorsArray(COLOR_QUADS * VERT_PER_QUAD); setValues(aColorsArray, StGLVec4(0.0f, 0.0f, 1.0f, 1.0f), 0 * VERT_PER_QUAD, VERT_PER_QUAD); // blue setValues(aColorsArray, StGLVec4(0.0f, 1.0f, 1.0f, 1.0f), 1 * VERT_PER_QUAD, VERT_PER_QUAD); // aqua setValues(aColorsArray, StGLVec4(1.0f, 0.0f, 1.0f, 1.0f), 2 * VERT_PER_QUAD, VERT_PER_QUAD); // fuchsia setValues(aColorsArray, StGLVec4(1.0f, 0.0f, 0.5f, 1.0f), 3 * VERT_PER_QUAD, VERT_PER_QUAD); // ? setValues(aColorsArray, StGLVec4(1.0f, 0.0f, 0.0f, 1.0f), 4 * VERT_PER_QUAD, VERT_PER_QUAD); // red setValues(aColorsArray, StGLVec4(1.0f, 0.5f, 0.0f, 1.0f), 5 * VERT_PER_QUAD, VERT_PER_QUAD); // orange setValues(aColorsArray, StGLVec4(1.0f, 1.0f, 0.0f, 1.0f), 6 * VERT_PER_QUAD, VERT_PER_QUAD); // yellow setValues(aColorsArray, StGLVec4(0.0f, 1.0f, 0.0f, 1.0f), 7 * VERT_PER_QUAD, VERT_PER_QUAD); // green myColors.changeVBO(ST_VBO_COLORS)->init(aCtx, aColorsArray); }