void DrawEnd() { IsRendererInitialized(); g_CurrentProgram->SetModelViewProjection(); g_CurrentProgram->SetUniform("color", g_CurrentColor); if(!g_DrawVertices->empty() && g_HasDrawBegun) { switch(g_Drawtype) { case CL_QUADS: DrawQuads(); break; case CL_TRIANGLES: DrawTriangles(*g_DrawVertices, *g_DrawTextureCoords, *g_DrawNormals); break; case CL_POINTS: DrawPoints(); break; case CL_LINES: DrawLines(); break; } } g_DrawVertices->clear(); g_DrawTextureCoords->clear(); g_DrawNormals->clear(); g_HasDrawBegun = false; g_CurrentProgram->ClearTextureUnits(); }
//==================================================================== // DebugDrawRangeCircle //==================================================================== void CAIDebugRenderer::DrawRangeCircle(const Vec3& vPos, float fRadius, float fWidth, const ColorB& colorFill, const ColorB& colorOutline, bool bDrawOutline) { const unsigned npts = 24; Vec3 points[npts]; Vec3 pointsOutline[npts]; Vec3 tris[npts * 2 * 3]; if (fWidth > fRadius) fWidth = fRadius; for (unsigned int i = 0; i < npts; i++) { float a = ((float)i / (float)npts) * gf_PI2; points[i] = Vec3(cosf(a), sinf(a), 0); pointsOutline[i] = vPos + points[i] * fRadius; } unsigned int n = 0; for (unsigned int i = 0; i < npts; i++) { tris[n++] = vPos + points[i] * (fRadius - fWidth); tris[n++] = vPos + points[i] * fRadius; tris[n++] = vPos + points[(i+1) % npts] * fRadius; tris[n++] = vPos + points[i] * (fRadius - fWidth); tris[n++] = vPos + points[(i+1) % npts] * fRadius; tris[n++] = vPos + points[(i+1) % npts] * (fRadius - fWidth); } DrawTriangles(tris, npts * 2 * 3, colorFill); if (bDrawOutline) DrawPolyline(pointsOutline, npts, true, colorOutline); }
//==================================================================== // DebugDrawRange //==================================================================== void CAIDebugRenderer::DrawRangeBox(const Vec3& vPos, const Vec3& vDir, float fSizeX, float fSizeY, float fWidth, const ColorB& colorFill, const ColorB& colorOutline, bool bDrawOutline) { float minX = fSizeX - fWidth; float maxX = fSizeX; float minY = fSizeY - fWidth; float maxY = fSizeY; if (maxX < 0.001f || maxY < 0.001f ||minX > maxX || minY > maxY) return; Vec3 points[8]; Vec3 tris[8 * 3]; Vec3 norm(vDir.y, -vDir.x, vDir.z); points[0] = vPos + norm * -minX + vDir * -minY; points[1] = vPos + norm * minX + vDir * -minY; points[2] = vPos + norm * minX + vDir * minY; points[3] = vPos + norm * -minX + vDir * minY; points[4] = vPos + norm * -maxX + vDir * -maxY; points[5] = vPos + norm * maxX + vDir * -maxY; points[6] = vPos + norm * maxX + vDir * maxY; points[7] = vPos + norm * -maxX + vDir * maxY; unsigned int n = 0; tris[n++] = points[0]; tris[n++] = points[5]; tris[n++] = points[1]; tris[n++] = points[0]; tris[n++] = points[4]; tris[n++] = points[5]; tris[n++] = points[1]; tris[n++] = points[6]; tris[n++] = points[2]; tris[n++] = points[1]; tris[n++] = points[5]; tris[n++] = points[6]; tris[n++] = points[2]; tris[n++] = points[7]; tris[n++] = points[3]; tris[n++] = points[2]; tris[n++] = points[6]; tris[n++] = points[7]; tris[n++] = points[3]; tris[n++] = points[4]; tris[n++] = points[0]; tris[n++] = points[3]; tris[n++] = points[7]; tris[n++] = points[4]; DrawTriangles(tris, 8 * 3, colorFill); if (bDrawOutline) DrawPolyline(&points[4], 4, true, colorOutline); }
void D3DInit() { //Set(); VideoOutInit(40*8); // LineBufferInit(); _fillRuns = (FillRunsProc)CopyProcToRam((void*)FillRuns,_fillRunsBuffer,sizeof(_fillRunsBuffer)); _fillLine = (FillLineProc)CopyProcToRam((void*)FillLine24,_fillLineBuffer,sizeof(_fillLineBuffer)); DrawTriangles(0x80,_appBuffer,sizeof(_appBuffer)); }
//==================================================================== // DebugDrawArrow //==================================================================== void CAIDebugRenderer::DrawArrow(const Vec3& vPos, const Vec3& vLength, float fWidth, const ColorB& color) { Vec3 points[7]; Vec3 tris[5 * 3]; float len = vLength.GetLength(); if (len < 0.0001f) return; float headLen = fWidth * 2.0f; float headWidth = fWidth * 2.0f; if (headLen > len * 0.8f) headLen = len * 0.8f; Vec3 vDir(vLength/len); Vec3 norm(vLength.y, -vLength.x, 0); norm.NormalizeSafe(); Vec3 end(vPos + vLength); Vec3 start(vPos); unsigned int n = 0; points[n++] = end; points[n++] = end - vDir * headLen - norm * headWidth/2; PREFAST_SUPPRESS_WARNING(6386) points[n++] = end - vDir * headLen - norm * fWidth/2; points[n++] = end - vDir * headLen + norm * fWidth/2; points[n++] = end - vDir * headLen + norm * headWidth/2; points[n++] = start - norm * fWidth/2; points[n++] = start + norm * fWidth/2; n = 0; tris[n++] = points[0]; tris[n++] = points[1]; tris[n++] = points[2]; tris[n++] = points[0]; tris[n++] = points[2]; tris[n++] = points[3]; tris[n++] = points[0]; tris[n++] = points[3]; tris[n++] = points[4]; tris[n++] = points[2]; tris[n++] = points[5]; tris[n++] = points[6]; tris[n++] = points[2]; tris[n++] = points[6]; tris[n++] = points[3]; DrawTriangles(tris, n, color); }
void COglshapeView::DrawWithOpenGL() { glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.0f, 0.0f, 0.0f); switch(m_shape) { case Points : DrawPoints(); break; case Lines : DrawLines(); break; case LineStrip : DrawLineStrip(); break; case LineLoop : DrawLineLoop(); break; case Polygons : DrawPolygons(); break; case Triangles : DrawTriangles(); break; case TriangleStrip : DrawTriangleStrip(); break; case TriangleFan : DrawTriangleFan(); break; case Quads : DrawQuads(); break; case QuadStrip : DrawQuadStrip(); break; case Nonconvex : DrawNonconvex(); break; } glFlush(); }
void ColoredPolygon::Draw() { _lastDrawMatrix = Render::GetCurrentMatrix(); DrawTriangles(); _screenDots.resize(_dots.size()); for (unsigned int i = 0; i < _dots.size(); ++i) { _screenDots[i] = _dots[i].pos; Render::GetCurrentMatrix().Mul(_screenDots[i]); } if (_triangles.GetVB().Size() == 0) { for (unsigned int i = 0; i < _dots.size(); ++i) { Render::Line(_dots[i].pos.x, _dots[i].pos.y, _dots[(i + 1) % _dots.size()].pos.x, _dots[(i + 1) % _dots.size()].pos.y, 0xFFFFFFFF); } } }
void nuiSoftwarePainter::DrawArray(nuiRenderArray* pArray) { if (!mEnableDrawArray) { pArray->Release(); return; } switch (pArray->GetMode()) { case GL_POINTS: //NGL_OUT(_T("GL_POINTS Not Implemented\n")); break; case GL_LINES: DrawLines(pArray); break; case GL_LINE_STRIP: DrawLineStrip(pArray); break; case GL_LINE_LOOP: DrawLineLoop(pArray); break; case GL_TRIANGLES: DrawTriangles(pArray); break; case GL_TRIANGLE_FAN: DrawTrianglesFan(pArray); break; case GL_TRIANGLE_STRIP: DrawTrianglesStrip(pArray); break; // case GL_QUADS: // DrawQuads(pArray); // break; // case GL_QUAD_STRIP: // DrawQuadStrip(pArray); // break; // case GL_POLYGON: // //NGL_OUT(_T("GL_POLYGON Not Implemented\n")); // break; } pArray->Release(); }
//==================================================================== // DebugDrawRangeArc //==================================================================== void CAIDebugRenderer::DrawRangeArc(const Vec3& vPos, const Vec3& vDir, float fAngle, float fRadius, float fWidth, const ColorB& colorFill, const ColorB& colorOutline, bool bDrawOutline) { const unsigned npts = 12; Vec3 points[npts]; Vec3 pointsOutline[npts]; Vec3 tris[(npts - 1) * 2 * 3]; Vec3 forw(vDir.x, vDir.y, 0.0f); forw.NormalizeSafe(); Vec3 right(forw.y, -forw.x, 0); if (fWidth > fRadius) fWidth = fRadius; for (unsigned int i = 0; i < npts; i++) { float a = ((float)i / (float)(npts - 1) - 0.5f) * fAngle; points[i] = forw * cosf(a) + right * sinf(a); pointsOutline[i] = vPos + points[i] * fRadius; } unsigned int n = 0; for (unsigned int i = 0; i < npts - 1; i++) { tris[n++] = vPos + points[i] * (fRadius - fWidth); tris[n++] = vPos + points[i+1] * fRadius; tris[n++] = vPos + points[i] * fRadius; tris[n++] = vPos + points[i] * (fRadius - fWidth); tris[n++] = vPos + points[i+1] * (fRadius - fWidth); tris[n++] = vPos + points[i+1] * fRadius; } DrawTriangles(tris, n, colorFill); if (bDrawOutline) { DrawPolyline(pointsOutline, npts, false, colorOutline); DrawLine(vPos + forw * (fRadius - fWidth/4), colorOutline, vPos + forw * (fRadius + fWidth/4), colorOutline); } }
bool RendererLegacy::DrawPointSprites(int count, const vector3f *positions, Material *material, float size) { if (count < 1 || !material || !material->texture0) return false; SetBlendMode(BLEND_ALPHA_ONE); SetDepthWrite(false); VertexArray va(ATTRIB_POSITION | ATTRIB_UV0, count * 6); matrix4x4f rot; glGetFloatv(GL_MODELVIEW_MATRIX, &rot[0]); rot.ClearToRotOnly(); rot = rot.InverseOf(); const float sz = 0.5f*size; const vector3f rotv1 = rot * vector3f(sz, sz, 0.0f); const vector3f rotv2 = rot * vector3f(sz, -sz, 0.0f); const vector3f rotv3 = rot * vector3f(-sz, -sz, 0.0f); const vector3f rotv4 = rot * vector3f(-sz, sz, 0.0f); //do two-triangle quads. Could also do indexed surfaces. //GL2 renderer should use actual point sprites //(see history of Render.cpp for point code remnants) for (int i=0; i<count; i++) { const vector3f &pos = positions[i]; va.Add(pos+rotv4, vector2f(0.f, 0.f)); //top left va.Add(pos+rotv3, vector2f(0.f, 1.f)); //bottom left va.Add(pos+rotv1, vector2f(1.f, 0.f)); //top right va.Add(pos+rotv1, vector2f(1.f, 0.f)); //top right va.Add(pos+rotv3, vector2f(0.f, 1.f)); //bottom left va.Add(pos+rotv2, vector2f(1.f, 1.f)); //bottom right } DrawTriangles(&va, material); SetBlendMode(BLEND_SOLID); SetDepthWrite(true); return true; }
int main() { InitGraphics(); packet_table[0].packet_count = GIF_PACKET_MAX; packet_table[0].packet = &packets[0][0]; packet_table[1].packet_count = GIF_PACKET_MAX; packet_table[1].packet = &packets[1][0]; /* // change Background color draw_env[0].bg_color.b = 255; draw_env[0].bg_color.r = 255; draw_env[0].bg_color.g = 255; draw_env[1].bg_color.b = 255; draw_env[1].bg_color.r = 255; draw_env[1].bg_color.g = 255; */ while(1) { active_buffer = GsDbGetDrawBuffer(); GsGifPacketsClear(&packet_table[active_buffer]); // clear the area that we are going to put the sprites/triangles/.... MovePoint(); DrawTriangles(&packet_table[active_buffer], active_buffer); //add stuff to the packet area GsDrawSync(0); //wait for the previous buffer to finish drawing GsVSync(0); //display the previous drawn buffer SelectDisplayContext( GsDbGetDisplayBuffer() ); //tell CRTC which context we want to see on our tv // clear the draw environment before we draw stuff on it ClearDrawingContext(active_buffer); GsGifPacketsExecute(&packet_table[active_buffer], 0); // '0' we dont have to wait because we have 2 buffers (GsDrawSync(0) will do the wait) GsDbSwapBuffer(); } return 0; }
void DrawScene(void) { /* clear the draw buffer */ glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); // clear the rasterization framebuffer memset(framebuffer, 0, 3*framebuffer_width*framebuffer_height); if (scene == 1) DrawTriangles(); else if (scene == 2) TestRasterizationSpeed(); else if (scene == 4) DrawPixels(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); if (scene != 9) { if (zoom) glOrtho(0, framebuffer_width, 0, framebuffer_height, -1, 1); else glOrtho(0, screen_width, 0, screen_height, -1, 1); // Draw textured quad glEnable(GL_TEXTURE_2D); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, framebuffer_width, framebuffer_height, 0, GL_RGB, GL_UNSIGNED_BYTE, framebuffer); glColor3f(1, 1, 1); glBegin(GL_QUADS); glTexCoord2i(0, 0); glVertex2i(0, 0); glTexCoord2i(1, 0); glVertex2i(framebuffer_width, 0); glTexCoord2i(1, 1); glVertex2i(framebuffer_width, framebuffer_height); glTexCoord2i(0, 1); glVertex2i(0, framebuffer_height); glEnd(); } else { if (zoom) glOrtho(-0.5, framebuffer_width-0.5, -0.5, framebuffer_height-0.5, -1, 1); else glOrtho(-0.5, screen_width-0.5, -0.5, screen_height-0.5, -1, 1); DrawTrianglesOpenGL(); glDisable(GL_TEXTURE_2D); glColor3f(1, 1, 0); glBegin(GL_POINTS); glVertex2i(0, 0); glVertex2i(framebuffer_width-1, framebuffer_height-1); glEnd(); } // finally, swap the draw buffers to make the triangles appear on screen glutSwapBuffers(); }
void DrawQuads() { if(g_DrawVertices->size() < 4 * 3) return; //Create verts to draw triangle std::vector<float> vertices; for(size_t i = 0; i < g_DrawVertices->size(); i += 12) { Vector3Df one((*g_DrawVertices)[i], (*g_DrawVertices)[i + 1], (*g_DrawVertices)[i + 2]); Vector3Df two((*g_DrawVertices)[i + 3], (*g_DrawVertices)[i + 4], (*g_DrawVertices)[i + 5]); Vector3Df three((*g_DrawVertices)[i + 6], (*g_DrawVertices)[i + 7], (*g_DrawVertices)[i + 8]); Vector3Df four((*g_DrawVertices)[i + 9], (*g_DrawVertices)[i + 10], (*g_DrawVertices)[i + 11]); AddToVector(vertices, one); AddToVector(vertices, two); AddToVector(vertices, three); AddToVector(vertices, one); AddToVector(vertices, three); AddToVector(vertices, four); } //Create verts to draw triangle std::vector<float> normals; for(size_t i = 0; i < g_DrawNormals->size(); i += 12) { Vector3Df one((*g_DrawNormals)[i], (*g_DrawNormals)[i + 1], (*g_DrawNormals)[i + 2]); Vector3Df two((*g_DrawNormals)[i + 3], (*g_DrawNormals)[i + 4], (*g_DrawNormals)[i + 5]); Vector3Df three((*g_DrawNormals)[i + 6], (*g_DrawNormals)[i + 7], (*g_DrawNormals)[i + 8]); Vector3Df four((*g_DrawNormals)[i + 9], (*g_DrawNormals)[i + 10], (*g_DrawNormals)[i + 11]); AddToVector(normals, one); AddToVector(normals, two); AddToVector(normals, three); AddToVector(normals, one); AddToVector(normals, three); AddToVector(normals, four); } std::vector<float> texCoord; //Create tex coords to draw triangle if(g_DrawTextureCoords->size() >= 4 * 2) //4 verts * 2 uv { for(size_t i = 0; i < g_DrawTextureCoords->size(); i += 8) { Vector2Df one((*g_DrawTextureCoords)[i], (*g_DrawTextureCoords)[i + 1]); Vector2Df two((*g_DrawTextureCoords)[i + 2], (*g_DrawTextureCoords)[i + 3]); Vector2Df three((*g_DrawTextureCoords)[i + 4], (*g_DrawTextureCoords)[i + 5]); Vector2Df four((*g_DrawTextureCoords)[i + 6], (*g_DrawTextureCoords)[i + 7]); AddToVector(texCoord, one); AddToVector(texCoord, two); AddToVector(texCoord, three); AddToVector(texCoord, one); AddToVector(texCoord, three); AddToVector(texCoord, four); } } DrawTriangles(vertices, texCoord, normals); }
void View::Draw(const Model &model) const { ofPushMatrix(); SetupViewpoint(); ofBackground(ofColor::white); //CHASERS------------------- for (int i = 0; i < model.nChasers; i++){ model.topChaser[i]->draw(); model.botChaser[i]->draw(); model.rightChaser[i]->draw(); model.leftChaser[i]->draw(); } DrawGravity(model); DrawPlayers(model); ofColor ball_color = model.last_hit_player == 1 ? color_p1 : model.last_hit_player == 2 ? color_p2 : ofColor::white; DrawBallTrail(model, model.ball_trail, ball_color); DrawStrikeIndicator(model); DrawBall(model.ball, ball_color); for (float x=-10; x<GRID_W; x+=(1.0/6.0)) { for (float y=-5; y<GRID_H; y+=(1.0/6.0)) { if (ofDist(model.ball->GetPosition().x, model.ball->GetPosition().y, x, y)<0.3) { if (ball_color==color_p1){ ofSetColor(color_p1.r,ofRandom(10,60),color_p1.b, 100); }else if(ball_color==color_p2){ ofSetColor(ofRandom(10,60),color_p2.g,color_p2.b, 100); }else{ ofSetColor(ofRandom(200,250),ofRandom(200,250),ofRandom(200,250), 200); } ofCircle(x, y, 0.1); } else if (ofDist(model.player1_top->GetPosition().x, model.player1_top->GetPosition().y, x, y)<0.4 || ofDist(model.player1_bottom->GetPosition().x, model.player1_bottom->GetPosition().y, x, y)<0.4) { ofSetColor(color_p1.r,ofRandom(10,60),color_p1.b, 155); ofCircle(x, y, 0.12); } else if (ofDist(model.player2_top->GetPosition().x, model.player2_top->GetPosition().y, x, y)<0.4 || ofDist(model.player2_bottom->GetPosition().x, model.player2_bottom->GetPosition().y, x, y)<0.4) { ofSetColor(ofRandom(10,60),color_p2.g,color_p2.b, 155); ofCircle(x, y, 0.12); } else if (ofDist(model.ball->GetPosition().x, model.ball->GetPosition().y, x, y)< model.p1glowMax){ ofNoFill(); ofSetColor(color_p1.r,ofRandom(10,60),color_p1.b, 135); ofCircle(x, y, 0.12); ofFill(); } else if (ofDist(model.ball->GetPosition().x, model.ball->GetPosition().y, x, y)< model.p2glowMax){ ofNoFill(); ofSetColor(ofRandom(10,60),color_p2.g,color_p2.b, 135); ofCircle(x, y, 0.12); ofFill(); } else { ofFill(); ofSetColor(ofRandom(0,10),ofRandom(0,10),ofRandom(10,20), 20); ofTriangle(x, y+0.7, x-0.6, y-0.6, x+0.6, y-0.6); } } } DrawCourt(model); DrawScore(model); if (model.show_winning_state) { DrawTriangles(model); } ofPopMatrix(); //DrawFramesPerSecond(model); }
int D3DLoop(int n) { _lasty = -1; _read = _write = _lastWrite = 0; _counter++; _vcounter += 6; if (_vcounter == 6*24) _vcounter = 0; _hacky = -1; DrawTriangles(0,_appBuffer,sizeof(_appBuffer)); // Start a new frame u8* write = _runs; u8* w = write; while (VideoOutLine() >= 22) // finishing last frame { w = DrawTrianglesLoop(_appBuffer,write); // Get ahead if (w) write = w; } // Start a new frame // int line; int geoTop = _hacky; // First y of geometric figure int bgTop = (240-128)>>1; // First y of bg int bgBottom = 240-bgTop; // Last y of bg int y = 255; // current y for (;;) { line = VideoOutLine(); if (y == 255) { if (line > (bgTop+22)) // Hit bg first { y = bgTop; break; } else if (line > (geoTop+22)) // Hit geometry first { while (line == VideoOutLine()) __WFI(); y = geoTop; break; } } w = DrawTrianglesLoop(_appBuffer,write); // Get ahead if (w) write = w; } u8* read = _runs; // count,left,runs u32 v = _vcounter; for (;;) { u8* dst = LineBufferGet(); bool bg = y >= bgTop && y < bgBottom; if (bg) { int c; line = y-bgTop; u32 p[6]; u8* pattern; if (line < 64) { // sky u32 color = ((_counter + line) >> 7) & 0x7; color |= color << 8; color |= color << 16; u32 add = (63-line)<<1; add |= add << 8; add |= add << 16; u32* src = (u32*)voronoidark + v; //src += v; u32 mask = 0xF8F8F8F8; p[0] = ((src[0] + add) & mask) | color; p[1] = ((src[1] + add) & mask) | color; p[2] = ((src[2] + add) & mask) | color; p[3] = ((src[3] + add) & mask) | color; p[4] = ((src[4] + add) & mask) | color; p[5] = ((src[5] + add) & mask) | color; pattern = (u8*)p; v += 6; if (v == 6*24) v = 0; } else { // Ground animation line &= 0x3F; c = ramp[line]; int r = _counter - c; u8 cr = 0; if ((r & 0x30) == 0x30) { if (line > 4) cr = (_counter >> 8) & 7; c += c>>1; if (c > 255) c = 255; } c &= 0xF8; c |= cr; pattern = (u8*)p; c |= c<<8; c |= c<<16; p[0] = p[1] = p[2] = p[3] = p[4] = p[5]= c; } _fillLine(dst,pattern,12); } else
void RenderScene(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glFrontFace(GL_CW); glUseProgram(shader); M3DVector3f at={1.5f, 0.0f, 0.0f}; M3DVector3f up={-1.0f, 0.0f, 1.0f}; M3DVector3f eye; float angle = timer.GetElapsedSeconds()*3.14159f/8; eye[0]= 6.8f * cos(angle); eye[1]= 6.0f * sin(angle); eye[2]= 30.0f; LookAt(cameraFrame,eye,at,up); M3DVector3f ambientLight = {1.0f, 1.0f, 1.0f}; M3DVector3f position = {10.0f, 10.0f, 5.0f}; M3DVector3f color = {1.0f, 1.0f, 1.0f}; float l_angle = 90.0f; float attenuation0 = 0.01f; float attenuation1 = 0.01f; float attenuation2 = 0.01f; M3DVector3f ambientColor = {0.0f, 1.0, 0.0}; M3DVector3f diffuseColor = {0.0f, 1.0f, 1.0f}; M3DVector3f specularColor = {1.0f, 1.0f, 1.0f}; float specularExponent = 8; projection.LoadMatrix(viewFrustum.GetProjectionMatrix()); modelView.PushMatrix(); M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelView.LoadMatrix(mCamera); modelView.PushMatrix(); glUniform3fv(shaderPositionLocation, 1, position); glUniform3fv(shaderColorLocation, 1, color); glUniform1f(shaderAngleLocation, angle); glUniform1f(shaderAttenuation0Location, attenuation0); glUniform1f(shaderAttenuation1Location, attenuation1); glUniform1f(shaderAttenuation2Location, attenuation2); glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix()); glUniformMatrix3fv(normalMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix()); glUniform3fv(ambientLightLocation, 1, ambientLight); glUniform3fv(shaderAmbientColorLocation, 1, ambientColor); glUniform3fv(shaderDiffuseColorLocation, 1, diffuseColor); glUniform3fv(shaderSpecularColorLocation, 1, specularColor); glUniform1f(shaderSpecularExponentLocation, specularExponent); glPolygonOffset(1.0f, 1.0f); grid(); glEnable(GL_POLYGON_OFFSET_FILL); grid(); glDisable(GL_POLYGON_OFFSET_FILL); modelView.PopMatrix(); modelView.PushMatrix(); modelView.Translate(-7.75f, -7.75f, 0.0f); modelView.Scale(0.25f, 0.25f, 0.25f); glUniform3fv(shaderPositionLocation, 1, position); glUniform3fv(shaderColorLocation, 1, color); glUniform1f(shaderAngleLocation, l_angle); glUniform1f(shaderAttenuation0Location, attenuation0); glUniform1f(shaderAttenuation1Location, attenuation1); glUniform1f(shaderAttenuation2Location, attenuation2); glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix()); glUniformMatrix3fv(normalMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix()); glUniform3fv(ambientLightLocation, 1, ambientLight); glUniform3fv(shaderAmbientColorLocation, 1, ambientColor); glUniform3fv(shaderDiffuseColorLocation, 1, diffuseColor); glUniform3fv(shaderSpecularColorLocation, 1, specularColor); glUniform1f(shaderSpecularExponentLocation, specularExponent); piramida(); modelView.PopMatrix(); modelView.PushMatrix(); modelView.Translate(-6.0f, -6.0f, 0.0f); modelView.Scale(0.5f, 0.5f, 0.5f); modelView.Rotate(angle*512, 0.0f, 0.0f, 2.0f); glUniform3fv(shaderPositionLocation, 1, position); glUniform3fv(shaderColorLocation, 1, color); glUniform1f(shaderAngleLocation, l_angle); glUniform1f(shaderAttenuation0Location, attenuation0); glUniform1f(shaderAttenuation1Location, attenuation1); glUniform1f(shaderAttenuation2Location, attenuation2); glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix()); glUniformMatrix3fv(normalMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix()); glUniform3fv(ambientLightLocation, 1, ambientLight); glUniform3fv(shaderAmbientColorLocation, 1, ambientColor); glUniform3fv(shaderDiffuseColorLocation, 1, diffuseColor); glUniform3fv(shaderSpecularColorLocation, 1, specularColor); glUniform1f(shaderSpecularExponentLocation, specularExponent); glDrawElements(GL_TRIANGLES,3*n_faces,GL_UNSIGNED_INT,0); modelView.PopMatrix(); modelView.PushMatrix(); modelView.Translate(-4.0f, -4.0f, 0.0f); modelView.Scale(0.75f, 0.75f, 0.75f); modelView.Rotate(angle*512, 0.0f, 2.0f, 0.0f); glUniform3fv(shaderPositionLocation, 1, position); glUniform3fv(shaderColorLocation, 1, color); glUniform1f(shaderAngleLocation, l_angle); glUniform1f(shaderAttenuation0Location, attenuation0); glUniform1f(shaderAttenuation1Location, attenuation1); glUniform1f(shaderAttenuation2Location, attenuation2); glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix()); glUniformMatrix3fv(normalMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix()); glUniform3fv(ambientLightLocation, 1, ambientLight); glUniform3fv(shaderAmbientColorLocation, 1, ambientColor); glUniform3fv(shaderDiffuseColorLocation, 1, diffuseColor); glUniform3fv(shaderSpecularColorLocation, 1, specularColor); glUniform1f(shaderSpecularExponentLocation, specularExponent); piramida(); modelView.PopMatrix();` modelView.PushMatrix(); modelView.Translate(2.0f, 2.0f, 0.0f); modelView.Scale(1.5f, 1.5f, 1.5f); modelView.Rotate(angle*512, 2.0f, 2.0f, 0.0f); glUniform3fv(shaderPositionLocation, 1, position); glUniform3fv(shaderColorLocation, 1, color); glUniform1f(shaderAngleLocation, l_angle); glUniform1f(shaderAttenuation0Location, attenuation0); glUniform1f(shaderAttenuation1Location, attenuation1); glUniform1f(shaderAttenuation2Location, attenuation2); glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix()); glUniformMatrix3fv(normalMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix()); glUniform3fv(ambientLightLocation, 1, ambientLight); glUniform3fv(shaderAmbientColorLocation, 1, ambientColor); glUniform3fv(shaderDiffuseColorLocation, 1, diffuseColor); glUniform3fv(shaderSpecularColorLocation, 1, specularColor); glUniform1f(shaderSpecularExponentLocation, specularExponent); piramida(); modelView.PopMatrix(); modelView.PushMatrix(); modelView.Translate(-1.5f, -1.5f, 0.0f); modelView.Rotate(angle*512, 2.0f, 0.0f, 0.0f); glUniform3fv(shaderPositionLocation, 1, position); glUniform3fv(shaderColorLocation, 1, color); glUniform1f(shaderAngleLocation, l_angle); glUniform1f(shaderAttenuation0Location, attenuation0); glUniform1f(shaderAttenuation1Location, attenuation1); glUniform1f(shaderAttenuation2Location, attenuation2); glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix()); glUniformMatrix3fv(normalMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix()); glUniform3fv(ambientLightLocation, 1, ambientLight); glUniform3fv(shaderAmbientColorLocation, 1, ambientColor); glUniform3fv(shaderDiffuseColorLocation, 1, diffuseColor); glUniform3fv(shaderSpecularColorLocation, 1, specularColor); glUniform1f(shaderSpecularExponentLocation, specularExponent); DrawTriangles(20, vertices_tab, faces_tab); modelView.PopMatrix(); modelView.PushMatrix(); modelView.Translate(6.5f, 6.5f, 0.0f); modelView.Scale(2.5f, 2.5f, 2.5f); modelView.Rotate(angle*512, 2.0f, 2.0f, 2.0f); glUniform3fv(shaderPositionLocation, 1, position); glUniform3fv(shaderColorLocation, 1, color); glUniform1f(shaderAngleLocation, l_angle); glUniform1f(shaderAttenuation0Location, attenuation0); glUniform1f(shaderAttenuation1Location, attenuation1); glUniform1f(shaderAttenuation2Location, attenuation2); glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix()); glUniformMatrix3fv(normalMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix()); glUniform3fv(ambientLightLocation, 1, ambientLight); glUniform3fv(shaderAmbientColorLocation, 1, ambientColor); glUniform3fv(shaderDiffuseColorLocation, 1, diffuseColor); glUniform3fv(shaderSpecularColorLocation, 1, specularColor); glUniform1f(shaderSpecularExponentLocation, specularExponent); DrawSmoothTriangles(20, vertices_tab, faces_tab); modelView.PopMatrix(); modelView.PopMatrix(); glutSwapBuffers(); glutPostRedisplay(); }
QGLWidgetTest::QGLWidgetTest(const QGLFormat& Format, QWidget *parent) : QGLWidget(Format, parent) { #else QGLWidgetTest::QGLWidgetTest(QWidget * parent) : QGLWidget(parent) { #endif #ifdef _DEBUG SysUtils::RedirectIOToConsole(); #endif GString s; GError err; // Depth Into The Screen gX = -8.0f; gY = -8.0f; gZ = -22.0f; gKernel = new GKernel(); // build path for data (textures) gDataPath = SysUtils::AmanithPath(); if (gDataPath.length() > 0) gDataPath += "data/"; gWireFrame = G_TRUE; gAnim = G_TRUE; gAng1 = gAng2 = gAng3 = 0; gFillRule = G_ODD_EVEN_RULE; gFillMode = 1; gStepAng1 = 0.004f; gStepAng2 = -0.002f; gStepAng3 = 0.001f; gAng1 = gAng2 = gAng3 = 0; // load the texture gTexture = (GPixelMap *)gKernel->CreateNew(G_PIXELMAP_CLASSID); if (!gTexture) abort(); s = gDataPath + "metal05.png"; err = gTexture->Load(StrUtils::ToAscii(s), "expandpalette=true"); if (err != G_NO_ERROR) abort(); } //------------------------------------------------------------ // destructor QGLWidgetTest::~QGLWidgetTest() { if (gKernel) delete gKernel; DeleteFont(); } //----- paintGL ---------------------------------------------- void QGLWidgetTest::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); setLightAndTransform(); if (gAnim) { gAng1 += gStepAng1; gAng2 += gStepAng2; gAng3 += gStepAng3; } // build the shape BuildShape(gAng1, gAng2, gAng3); // triangulate GenerateTessellation(); DrawTriangles(gTrianglesPts, gTrianglesIdx); glFlush(); }