static void engine_draw_frame(struct engine* engine) { if (engine->display == NULL) return; LOGI("start draw"); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glUseProgram(g_program[MODEL]); //glUniformMatrix4fv(g_slots[MODEL][PROJECTION], 1, 0, projection.getMatrix()); //glUniformMatrix4fv(g_slots[MODEL][MODELMAT], 1, 0, modelmat.getMatrix()); //glUniformMatrix4fv(g_slots[MODEL][VIEWMAT], 1, 0, viewmat.getMatrix()); glEnableVertexAttribArray(g_slots[MODEL][POSITION]); glEnableVertexAttribArray(g_slots[MODEL][TEXCOORD]); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); DrawArray(); // <-- Try commenting out this line glUseProgram(g_program[ORTHO]); glUniform1f(g_slots[ORTHO][WIDTH], (float)g_width); glUniform1f(g_slots[ORTHO][HEIGHT], (float)g_height); glEnableVertexAttribArray(g_slots[ORTHO][POSITION]); glEnableVertexAttribArray(g_slots[ORTHO][TEXCOORD]); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); DrawImage(g_img, 0, 0, 300, 300); eglSwapBuffers(engine->display, engine->surface); }
void nuiGLDrawContext::DrawObject(const nuiRenderObject& rObject) { uint32 count = rObject.GetSize(); for (uint32 i = 0; i < count; i++) { DrawArray(*(rObject.GetArray(i))); } }
void nuiDrawContext::DrawImageQuad(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3, const nuiRect& rSource) { bool texturing = mCurrentState.mTexturing; if (!texturing) EnableTexturing(true); nuiSize tx0,tx1,tx2,tx3; nuiSize ty0,ty1,ty2,ty3; tx0 = rSource.mLeft; ty0 = rSource.mTop; tx1 = rSource.mRight; ty1 = rSource.mTop; tx2 = rSource.mRight; ty2 = rSource.mBottom; tx3 = rSource.mLeft; ty3 = rSource.mBottom; mCurrentState.mpTexture[0]->ImageToTextureCoord(tx0, ty0); mCurrentState.mpTexture[0]->ImageToTextureCoord(tx1, ty1); mCurrentState.mpTexture[0]->ImageToTextureCoord(tx2, ty2); mCurrentState.mpTexture[0]->ImageToTextureCoord(tx3, ty3); nuiRenderArray* pArray = new nuiRenderArray(GL_TRIANGLE_STRIP); pArray->Reserve(4); pArray->EnableArray(nuiRenderArray::eVertex, true); pArray->EnableArray(nuiRenderArray::eTexCoord, true); pArray->EnableArray(nuiRenderArray::eColor, true); // 1 pArray->SetTexCoords(tx0,ty0); pArray->SetVertex(x0, y0); pArray->SetColor(mCurrentState.mFillColor); pArray->PushVertex(); pArray->SetTexCoords(tx3,ty3); pArray->SetVertex(x3, y3); pArray->PushVertex(); pArray->SetTexCoords(tx1,ty1); pArray->SetVertex(x1, y1); pArray->PushVertex(); // 2 pArray->SetTexCoords(tx2,ty2); pArray->SetVertex(x2, y2); pArray->PushVertex(); DrawArray(pArray); if (!texturing) EnableTexturing(texturing); }
void CTracerProjectile::Draw() { if(inArray) DrawArray(); if(drawLength>3) drawLength=3; float3 interPos=pos+speed*gu->timeOffset; glTexCoord2f(1.0f/16,1.0f/16); glColor4f(1,1,0.1f,0.4f); glBegin(GL_LINES); glVertexf3( interPos); glVertexf3( interPos-dir*drawLength); glEnd(); }
void nuiDrawContext::DrawRect(const nuiRect& rRect, nuiShapeMode Mode) { if (Mode == eStrokeAndFillShape || Mode == eStrokeShape) { nuiRect rect(rRect); GLenum mode = GL_LINE_LOOP; if (rect.mRight - rect.mLeft <= 1.0f) { mode = GL_TRIANGLE_STRIP; } else { rect.mRight -= 1.0f; } if (rect.mBottom - rect.mTop <= 1.0f) { mode = GL_TRIANGLE_STRIP; } else { rect.mBottom -= 1.0f; } // Draw the stroke in all cases: if (mode == GL_TRIANGLE_STRIP) { nuiRenderArray* pStrokeArray = new nuiRenderArray(mode); pStrokeArray->EnableArray(nuiRenderArray::eVertex, true); pStrokeArray->EnableArray(nuiRenderArray::eColor, true); pStrokeArray->Reserve(4); pStrokeArray->SetColor(mCurrentState.mStrokeColor); pStrokeArray->SetVertex(rect.mLeft, rect.mTop); pStrokeArray->PushVertex(); pStrokeArray->SetVertex(rect.mRight, rect.mTop); pStrokeArray->PushVertex(); pStrokeArray->SetVertex(rect.mLeft, rect.mBottom); pStrokeArray->PushVertex(); pStrokeArray->SetVertex(rect.mRight, rect.mBottom); pStrokeArray->PushVertex(); DrawArray(pStrokeArray); } else { nuiRenderArray* pStrokeArray = new nuiRenderArray(mode); if (nuiGetScaleFactor() != 1.0f) { nuiDrawRect(rRect, *pStrokeArray); } else { pStrokeArray->EnableArray(nuiRenderArray::eVertex, true); pStrokeArray->EnableArray(nuiRenderArray::eColor, true); pStrokeArray->Reserve(4); pStrokeArray->SetColor(mCurrentState.mStrokeColor); pStrokeArray->SetVertex(rect.mLeft, rect.mTop); pStrokeArray->PushVertex(); pStrokeArray->SetVertex(rect.mRight, rect.mTop); pStrokeArray->PushVertex(); pStrokeArray->SetVertex(rect.mRight, rect.mBottom); pStrokeArray->PushVertex(); pStrokeArray->SetVertex(rect.mLeft, rect.mBottom); pStrokeArray->PushVertex(); } DrawArray(pStrokeArray); } } if (Mode == eStrokeAndFillShape) { if ((rRect.mRight - rRect.mLeft <= 2.0f) || (rRect.mBottom - rRect.mTop <= 2.0f)) return; nuiRect rect(rRect); // Draw the filled part: nuiRenderArray* pFillArray = new nuiRenderArray(GL_TRIANGLE_STRIP); pFillArray->EnableArray(nuiRenderArray::eVertex, true); pFillArray->EnableArray(nuiRenderArray::eColor, true); pFillArray->Reserve(4); pFillArray->SetColor(mCurrentState.mFillColor); pFillArray->SetVertex(rect.mLeft+1, rect.mTop+1); pFillArray->PushVertex(); pFillArray->SetVertex(rect.mRight-1, rect.mTop+1); pFillArray->PushVertex(); pFillArray->SetVertex(rect.mLeft+1, rect.mBottom-1); pFillArray->PushVertex(); pFillArray->SetVertex(rect.mRight-1, rect.mBottom-1); pFillArray->PushVertex(); DrawArray(pFillArray); } else if (Mode == eFillShape) { nuiRect rect(rRect); //rect.Move(0,-.5); // Adjust to have a correct position on ATI cards, this should work on nvidia too // Draw the filled rectangle: nuiRenderArray* pFillArray = new nuiRenderArray(GL_TRIANGLE_STRIP); pFillArray->EnableArray(nuiRenderArray::eVertex, true); pFillArray->EnableArray(nuiRenderArray::eColor, true); pFillArray->Reserve(4); pFillArray->SetColor(mCurrentState.mFillColor); pFillArray->SetVertex(rect.mLeft, rect.mTop); pFillArray->PushVertex(); pFillArray->SetVertex(rect.mRight, rect.mTop); pFillArray->PushVertex(); pFillArray->SetVertex(rect.mLeft, rect.mBottom); pFillArray->PushVertex(); pFillArray->SetVertex(rect.mRight, rect.mBottom); pFillArray->PushVertex(); DrawArray(pFillArray); } }
void nuiDrawContext::DrawGradient(const nuiGradient& rGradient, const nuiRect& rEnclosingRect, nuiSize x1, nuiSize y1, nuiSize x2, nuiSize y2) { nuiVector2 vec(x2 - x1, y2 - y1); nuiVector2 para(-vec[1], vec[0]); nuiVector2 vec1(vec); nuiVector2 para1(para); vec1.Normalize(); para1.Normalize(); // What Quadrant are we in?: // | // a | b // | // ---------------- // | // c | d // | float xa, xb, xc, xd; float ya, yb, yc, yd; float x, y; float xp, yp; float xx, yy; float xxp, yyp; xa = xc = rEnclosingRect.Left(); xb = xd = rEnclosingRect.Right(); ya = yb = rEnclosingRect.Top(); yc = yd = rEnclosingRect.Bottom(); if (x1 < x2) { // Go from a to d or c to b if (y1 == y2) { x = xa; y = ya; xp = xc; yp = yc; xx = xd; yy = yd; xxp= xb; yyp= yb; } else if (y1 < y2) { // a to d IntersectLines(xa,ya, para1[0], para1[1], xb, yb, vec1[0], vec1[1], x, y); IntersectLines(xa,ya, para1[0], para1[1], xc, yc, vec1[0], vec1[1], xp, yp); IntersectLines(xd,yd, para1[0], para1[1], xc, yc, vec1[0], vec1[1], xx, yy); IntersectLines(xd,yd, para1[0], para1[1], xb, yb, vec1[0], vec1[1], xxp, yyp); } else { // c to d IntersectLines(xc,yc, para1[0], para1[1], xa, ya, vec1[0], vec1[1], x, y); IntersectLines(xc,yc, para1[0], para1[1], xd, yd, vec1[0], vec1[1], xp, yp); IntersectLines(xb,yb, para1[0], para1[1], xd, yd, vec1[0], vec1[1], xx, yy); IntersectLines(xb,yb, para1[0], para1[1], xa, ya, vec1[0], vec1[1], xxp, yyp); } } else { if (y1 == y2) { x = xd; y = yd; xp = xb; yp = yb; xx = xa; yy = ya; xxp= xc; yyp= yc; } else if (y1 < y2) { // b to c IntersectLines(xb,yb, para1[0], para1[1], xd, yd, vec1[0], vec1[1], x, y); IntersectLines(xb,yb, para1[0], para1[1], xa, ya, vec1[0], vec1[1], xp, yp); IntersectLines(xc,yc, para1[0], para1[1], xa, ya, vec1[0], vec1[1], xx, yy); IntersectLines(xc,yc, para1[0], para1[1], xd, yd, vec1[0], vec1[1], xxp, yyp); } else { // d to a IntersectLines(xd,yd, para1[0], para1[1], xc, yc, vec1[0], vec1[1], x, y); IntersectLines(xd,yd, para1[0], para1[1], xb, yb, vec1[0], vec1[1], xp, yp); IntersectLines(xa,ya, para1[0], para1[1], xb, yb, vec1[0], vec1[1], xx, yy); IntersectLines(xa,ya, para1[0], para1[1], xc, yc, vec1[0], vec1[1], xxp, yyp); } } float startx,starty; float startxp,startyp; float stopx,stopy; float stopxp,stopyp; if (y1 != y2) { IntersectLines(x1, y1, para1[0], para1[1], x, y, vec1[0], vec1[1], startx, starty); IntersectLines(x1, y1, para1[0], para1[1], xp, yp, vec1[0], vec1[1], startxp, startyp); IntersectLines(x2, y2, para1[0], para1[1], x, y, vec1[0], vec1[1], stopx, stopy); IntersectLines(x2, y2, para1[0], para1[1], xp, yp, vec1[0], vec1[1], stopxp, stopyp); } else { startx = x1; starty = y; startxp = x1; startyp = yp; stopx = x2; stopy = y; stopxp = x2; stopyp = yp; } nuiGradientStopList::const_iterator it = rGradient.GetStopList().begin(); nuiGradientStopList::const_iterator end = rGradient.GetStopList().end(); float px1, py1; float px2, py2; PushClipping(); Clip(rEnclosingRect); EnableClipping(true); nuiRenderArray* pArray = new nuiRenderArray(GL_TRIANGLE_STRIP); pArray->EnableArray(nuiRenderArray::eVertex); pArray->EnableArray(nuiRenderArray::eColor); // nuiRenderArray Array(GL_LINES); // pArray->SetVertexElements(3); // pArray->SetColorElements(4); nuiColor col = it->second; pArray->SetVertex(x, y); pArray->SetColor(col); pArray->PushVertex(); pArray->SetVertex(xp, yp); pArray->PushVertex(); for ( ; it != end; ++it) { float r = it->first; float rm = 1.0f - r; px1 = startx * rm + stopx * r; py1 = starty * rm + stopy * r; px2 = startxp * rm + stopxp * r; py2 = startyp * rm + stopyp * r; col = it->second; pArray->SetColor(col); pArray->SetVertex(px2, py2); pArray->PushVertex(); pArray->SetVertex(px1, py1); pArray->PushVertex(); } pArray->SetVertex(xx, yy); pArray->PushVertex(); pArray->SetVertex(xxp, yyp); pArray->PushVertex(); DrawArray(pArray); PopClipping(); }
void nuiDrawContext::DrawShade(const nuiRect& rSourceRect, const nuiRect& rShadeRect, const nuiColor& rTint) { bool texturing = mCurrentState.mTexturing; bool blending = mCurrentState.mBlending; nuiBlendFunc blendfunc; blendfunc = mCurrentState.mBlendFunc; if (!blending) EnableBlending(true); if (blendfunc != nuiBlendTransp) SetBlendFunc(nuiBlendTransp); nuiSize ShadeSize = rSourceRect.mLeft - rShadeRect.mLeft; nuiTexture* pShade = ::nuiTexture::GetTexture(nglString(_T("NUI_Shade_LUT"))); if (!pShade) { // Left shadow const uint32 size = 16; uint8 pLUT[size * 4]; uint i; for (i = 0; i<size; i++) { pLUT[0+(i*4)] = 0; pLUT[1+(i*4)] = 0; pLUT[2+(i*4)] = 0; float p = (float)i * (255.0f / (float)size); pLUT[3+(i*4)] = ToBelow(p); } nglImageInfo info(false); info.mBitDepth = 32; info.mBufferFormat = eImageFormatRaw; info.mBytesPerLine = size * 4; info.mBytesPerPixel = 4; info.mHeight = 1; info.mWidth = size; info.mpBuffer = (char*)pLUT; info.mPixelFormat = eImagePixelRGBA; pShade = nuiTexture::GetTexture(info, true); pShade->SetSource(_T("NUI_Shade_LUT")); NGL_ASSERT(pShade); pShade->SetMinFilter(GL_LINEAR); pShade->SetMagFilter(GL_LINEAR); #ifndef _OPENGL_ES_ pShade->SetWrapS(GL_CLAMP); pShade->SetWrapT(GL_CLAMP); #else pShade->SetWrapS(GL_CLAMP_TO_EDGE); pShade->SetWrapT(GL_CLAMP_TO_EDGE); #endif pShade->SetEnvMode(GL_MODULATE); } nuiColor transp(rTint); nuiColor opaque(rTint); transp.Multiply(0.0f); opaque.Multiply(SHADE_ALPHA); if (!texturing) EnableTexturing(true); SetTexture(pShade); nuiRenderArray* pArray = new nuiRenderArray(GL_TRIANGLES); pArray->EnableArray(nuiRenderArray::eVertex); pArray->EnableArray(nuiRenderArray::eColor); pArray->EnableArray(nuiRenderArray::eTexCoord); pArray->Reserve(42); // Top Left: pArray->SetColor(transp); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mTop); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mTop); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); /// pArray->SetColor(transp); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mTop); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetTexCoords(0, 0); pArray->SetColor(opaque); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); // Left pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom); pArray->PushVertex(); /// pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mBottom); pArray->PushVertex(); // Left Corner: pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); /// pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); // bottom shadow pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); /// pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); // Right Corner pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); /// pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); // Right pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mBottom); pArray->PushVertex(); /// pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom); pArray->PushVertex(); // Top Right pArray->SetColor(transp); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mTop); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mTop); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); /// pArray->SetColor(transp); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mTop); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); DrawArray(pArray); if (!texturing) EnableTexturing(false); if (!blending) EnableBlending(blending); if (blendfunc != nuiBlendTransp) SetBlendFunc(blendfunc); }