Disk::Disk(Graphics::Renderer *r, RefCountedPtr<Material> material, Graphics::RenderState *state, const int edges, const float rad) : m_material(material) { PROFILE_SCOPED() m_renderState = state; VertexArray vertices (ATTRIB_POSITION); vertices.Add(vector3f(0.f, 0.f, 0.f)); const float edgeStep = 360.0f / float(edges); for (int i = edges; i >= 0; i--) { vertices.Add(vector3f( 0.f+sinf(DEG2RAD(i*edgeStep))*rad, 0.f+cosf(DEG2RAD(i*edgeStep))*rad, 0.f)); } SetupVertexBuffer(vertices, r); }
void Render(const Mat4f& model) { prog.Use(); model_matrix.Set(model); // bind the VAO sphere.Bind(); // use the instructions to draw the sphere // (this basically calls glDrawArrays* or glDrawElements*) sphere_instr.Draw(sphere_indices); }
void AiCarStandard::AddLinePoint(VertexArray & va, const Vec3 & p) { int vsize; const float* vbase; va.GetVertices(vbase, vsize); if (vsize == 0) { int vcount = 3; float verts[3] = {p[0], p[1], p[2]}; va.SetVertices(verts, vcount, vsize); } else { int vcount = 6; float verts[6] = {p[0], p[1], p[2], p[0], p[1], p[2]}; va.SetVertices(verts, vcount, vsize); } }
Disk::Disk(Graphics::Renderer *r, Graphics::RenderState *state, const Color &c, float rad) { PROFILE_SCOPED() m_renderState = state; VertexArray vertices (ATTRIB_POSITION); m_material.Reset(r->CreateMaterial(MaterialDescriptor())); m_material->diffuse = c; vertices.Add(vector3f(0.f, 0.f, 0.f)); for (int i = 72; i >= 0; i--) { vertices.Add(vector3f( 0.f+sinf(DEG2RAD(i*5.f))*rad, 0.f+cosf(DEG2RAD(i*5.f))*rad, 0.f)); } SetupVertexBuffer(vertices, r); }
bool CarGraphics::LoadLight( const PTree & cfg, ContentManager & content, std::ostream & error_output) { float radius; std::string radiusstr; Vec3 pos(0), col(0); if (!cfg.get("position", pos, error_output)) return false; if (!cfg.get("color", col, error_output)) return false; if (!cfg.get("radius", radius, error_output)) return false; cfg.get("radius", radiusstr); lights.push_back(Light()); SceneNode & bodynoderef = topnode.GetNode(bodynode); lights.back().node = bodynoderef.AddNode(); SceneNode & node = bodynoderef.GetNode(lights.back().node); node.GetTransform().SetTranslation(Vec3(pos[0], pos[1], pos[2])); std::shared_ptr<Model> mesh; if (!content.get(mesh, "", "cube" + radiusstr)) { VertexArray varray; varray.SetToUnitCube(); varray.Scale(radius, radius, radius); content.load(mesh, "", "cube" + radiusstr, varray); } models.insert(mesh); keyed_container <Drawable> & dlist = node.GetDrawList().lights_omni; lights.back().draw = dlist.insert(Drawable()); Drawable & draw = dlist.get(lights.back().draw); draw.SetColor(col[0], col[1], col[2]); draw.SetModel(*mesh); draw.SetCull(true); draw.SetDrawEnable(false); return true; }
VertexArray VertexArray::operator+ (const VertexArray & v) const { VertexArray out; COMBINEVECTORS(colors); COMBINEVECTORS(normals); COMBINEVECTORS(vertices); int idxoffset = vertices.size() / 3; out.faces.reserve(faces.size() + v.faces.size()); out.faces.insert(out.faces.end(), faces.begin(), faces.end()); for (size_t i = 0; i < v.faces.size(); i++) { out.faces.push_back(v.faces[i]+idxoffset); } int maxtcsets = GetTexCoordSets(); if (v.GetTexCoordSets() > maxtcsets) maxtcsets = v.GetTexCoordSets(); int tcsets1 = GetTexCoordSets(); int tcsets2 = v.GetTexCoordSets(); out.SetTexCoordSets(maxtcsets); for (int i = 0; i < maxtcsets; i++) { if (i >= tcsets1 && i < tcsets2) { out.texcoords[i] = v.texcoords[i]; } else if (i < tcsets1 && i >= tcsets2) { out.texcoords[i] = texcoords[i]; } else if (i < tcsets1 && i < tcsets2) { COMBINEVECTORS(texcoords[i]); } } return out; }
Shape(const Program& prog) : vbos(4) , point_count(4096) { // bind the VAO for the shape vao.Bind(); make_shape_1(prog, 0, "Position1"); make_shape_2(prog, 1, "Position2"); make_radiance(prog, 2, "Radiance1"); make_radiance(prog, 3, "Radiance2"); }
void Game::render() { glClearColor( 0.1, 0.1, 0.1, 1.0 ); glClear( GL_COLOR_BUFFER_BIT ); RenderStates defRenderStates; temp.resize( 4 ); temp.setPrimitiveType( PrimitiveType::PType_Quads ); temp[ 0 ].pos = Vec2f( 0, 0 ); temp[ 1 ].pos = Vec2f( 1, 0 ); temp[ 2 ].pos = Vec2f( 1, 1 ); temp[ 3 ].pos = Vec2f( 0, 1 ); m_renderer.draw( temp, defRenderStates ); if( m_gameState ) { m_gameState->render( m_renderer, defRenderStates ); } SDL_GL_SwapWindow( m_window ); }
VertexArray<float>* Model::getVArrayPtr(MetaGroup* _grp) { VertexArray<float>* va = new VertexArray<float>(4); va->mData = new float[_grp->nVertices*4]; va->stride = 4*sizeof(float); va->size = _grp->nVertices; size_t posCount = 0; vector<Face*>::const_iterator face_it; for (face_it = _grp->fPtrList.begin(); face_it != _grp->fPtrList.end(); ++face_it){ vector<V3f *>::const_iterator v_it; for (v_it=(*face_it)->vertexPtrList.begin(); v_it!=(*face_it)->vertexPtrList.end(); ++v_it){ va->mData[posCount++] = (*v_it)->getX(); va->mData[posCount++] = (*v_it)->getY(); va->mData[posCount++] = (*v_it)->getZ(); va->mData[posCount++] = mPriCTable.calculateTexCoord(mPriCTable.addColori(_grp->getMat())); } } va->setBB(*_grp->bb); return va; }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); auto camera = CamMatrixf::Orbiting( Vec3f(), 8.5, FullCircles(time / 5.0), Degrees(15 + (-SineWave(time/10.0)+1.0)* 0.5 * 75) ); ModelMatrixf model = ModelMatrixf::Translation(0.0f, 2.5f, 0.0) * ModelMatrixf::RotationA( Vec3f(1.0f, 1.0f, 1.0f), FullCircles(time / 7.0) ); plane_prog.Use(); plane_camera_matrix.Set(camera); plane.Bind(); gl.DrawArrays(PrimitiveType::TriangleStrip, 0, 4); shape_prog.Use(); shape_camera_matrix.Set(camera); shape_model_matrix.Set(model); shape.Bind(); shape_instr.Draw(shape_indices); halo_prog.Use(); halo_camera_matrix.Set(camera); halo_model_matrix.Set(model); gl.DepthMask(false); gl.Enable(Capability::Blend); shape_instr.Draw(shape_indices); gl.Disable(Capability::Blend); gl.DepthMask(true); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); auto cameraMatrix = CamMatrixf::Orbiting( Vec3f(0.0f, 3.0f, 0.0f), 8.0f, FullCircles(time / 12.0), Degrees(SineWave(time / 20.0) * 80) ); plane.Bind(); plane_prog.Use(); Uniform<Mat4f>(plane_prog, "CameraMatrix").Set(cameraMatrix); gl.DrawArrays(PrimitiveType::TriangleStrip, 0, 4); gl.Enable(Capability::Blend); volume.Bind(); volume_prog.Use(); Uniform<Mat4f>(volume_prog, "CameraMatrix").Set(cameraMatrix); Uniform<Vec3f>(volume_prog, "ViewX").Set( cameraMatrix.Row(0).xyz() ); Uniform<Vec3f>(volume_prog, "ViewY").Set( cameraMatrix.Row(1).xyz() ); Uniform<Vec3f>(volume_prog, "ViewZ").Set( cameraMatrix.Row(2).xyz() ); gl.DrawArraysInstanced( PrimitiveType::Points, 0, 1, samples ); gl.Disable(Capability::Blend); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); auto lightPos = light_path.Position(time * 0.05); auto cameraMatrix = CamMatrixf::Orbiting( Vec3f(), 4.5f, Degrees(0), Degrees(SineWave(time / 20.0) * 80) ); light.Bind(); light_prog.Use(); Uniform<Vec3f>(light_prog, "LightPos").Set(lightPos); Uniform<Mat4f>(light_prog, "CameraMatrix").Set(cameraMatrix); sphere_instr.Draw(sphere_indices); clouds.Bind(); cloud_prog.Use(); Uniform<Vec3f>(cloud_prog, "LightPos").Set(lightPos); Uniform<Mat4f>(cloud_prog, "CameraMatrix").Set(cameraMatrix); Uniform<Vec4f>(cloud_prog, "ViewX").Set(cameraMatrix.Row(0)); Uniform<Vec4f>(cloud_prog, "ViewY").Set(cameraMatrix.Row(1)); Uniform<Vec4f>(cloud_prog, "ViewZ").Set(cameraMatrix.Row(2)); for(std::size_t i=0, n=positions.size(); i!=n; ++i) { cloud_tex[i].Bind(Texture::Target::_3D); gl.DrawArraysInstanced( PrimitiveType::Points, i, 1, samples ); } }
void Starfield::Fill(unsigned long seed) { VertexArray *va = m_model->GetSurface(0)->GetVertices(); va->Clear(); // clear if previously filled // Slight colour variation to stars based on seed MTRand rand(seed); //fill the array for (int i=0; i<BG_STAR_MAX; i++) { float col = float(rand.Double(0.2,0.7)); // this is proper random distribution on a sphere's surface const float theta = float(rand.Double(0.0, 2.0*M_PI)); const float u = float(rand.Double(-1.0, 1.0)); va->Add(vector3f( 1000.0f * sqrt(1.0f - u*u) * cos(theta), 1000.0f * u, 1000.0f * sqrt(1.0f - u*u) * sin(theta) ), Color(col, col, col, 1.f) ); } }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); CamMatrixf camera = CamMatrixf::Orbiting( Vec3f(), 4.5f + float(SineWave(time / 25.0)), FullCircles(time / 30.0), Degrees(SineWave(time / 19.0) * 20) ); light_prog.camera_matrix.Set(camera); flare_prog.camera_matrix.Set(camera); shape_prog.camera_matrix.Set(camera); shape_prog.camera_position.Set(camera.Position()); shape_prog.model_matrix.Set( ModelMatrixf::RotationX(FullCircles(time / 30.0)) ); shape_prog.Use(); shape.Draw(); NoProgram().Use(); lights.Bind(); light_prog.Use(); for(GLuint l=0; l!=n_flares; ++l) { queries[l].Begin(Query::Target::SamplesPassed); gl.DrawArrays(PrimitiveType::Points, l, 1); queries[l].End(Query::Target::SamplesPassed); } gl.Enable(Capability::Blend); gl.Disable(Capability::DepthTest); flare_prog.Use(); for(GLuint l=0; l!=n_flares; ++l) { GLint samples = 0; queries[l].WaitForResult(samples); if(samples != 0) { flare_prog.samples = samples; gl.DrawArrays(PrimitiveType::Points, l, 1); } } gl.Enable(Capability::DepthTest); gl.Disable(Capability::Blend); }
void draw(const VertexArray &varray, const IndexArray &iarray) { load_xform_matrices(); bool use_vbo = !varray.get_dynamic() && sys_caps.vertex_buffers; bool use_ibo = false;//!iarray.get_dynamic() && sys_caps.vertex_buffers; glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); if(use_vbo) { Vertex v; glBindBuffer(GL_ARRAY_BUFFER_ARB, varray.get_buffer_object()); glVertexPointer(3, GL_SCALAR_TYPE, sizeof(Vertex), (void*)((char*)&v.pos - (char*)&v)); glNormalPointer(GL_SCALAR_TYPE, sizeof(Vertex), (void*)((char*)&v.normal - (char*)&v)); glColorPointer(4, GL_SCALAR_TYPE, sizeof(Vertex), (void*)((char*)&v.color - (char*)&v)); for(int i=0; i<MAX_TEXTURES; i++) { select_texture_unit(i); glEnableClientState(GL_TEXTURE_COORD_ARRAY); int dim = ttype[i] == TEX_1D ? 1 : (ttype[i] == TEX_3D || ttype[i] == TEX_CUBE ? 3 : 2); glTexCoordPointer(dim, GL_SCALAR_TYPE, sizeof(Vertex), (void*)((char*)&v.tex[coord_index[i]] - (char*)&v)); } glBindBuffer(GL_ARRAY_BUFFER_ARB, 0); } else { glVertexPointer(3, GL_SCALAR_TYPE, sizeof(Vertex), &varray.get_data()->pos); glNormalPointer(GL_SCALAR_TYPE, sizeof(Vertex), &varray.get_data()->normal); glColorPointer(4, GL_SCALAR_TYPE, sizeof(Vertex), &varray.get_data()->color); for(int i=0; i<MAX_TEXTURES; i++) { select_texture_unit(i); glEnableClientState(GL_TEXTURE_COORD_ARRAY); int dim = ttype[i] == TEX_1D ? 1 : (ttype[i] == TEX_3D || ttype[i] == TEX_CUBE ? 3 : 2); glTexCoordPointer(dim, GL_SCALAR_TYPE, sizeof(Vertex), &varray.get_data()->tex[coord_index[i]]); } } if(use_ibo) { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, iarray.get_buffer_object()); glDrawElements(primitive_type, iarray.get_count(), GL_UNSIGNED_INT, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); } else { glDrawElements(primitive_type, iarray.get_count(), GL_UNSIGNED_INT, iarray.get_data()); } glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); for(int i=0; i<MAX_TEXTURES; i++) { select_texture_unit(i); glDisableClientState(GL_TEXTURE_COORD_ARRAY); } }
void drawVertArray(GLenum shape,const VertexArray& varr) { glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glVertexPointer(3,GL_FLOAT,sizeof(Vertex),&varr[0].loc[0]); glColorPointer(3,GL_FLOAT,sizeof(Vertex),&varr[0].color[0]); glNormalPointer(GL_FLOAT,sizeof(Vertex),&varr[0].normal[0]); glDrawArrays(shape,0,varr.size()); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); }
RippleGenerator(GLuint first_tex_unit) : size(1024) , prog(size) , holder(size, first_tex_unit) { fbo.Bind(Framebuffer::Target::Draw); Framebuffer::AttachColorTexture( Framebuffer::Target::Draw, 0, holder.BumpMap(), 0 ); vao.Bind(); }
Particle(const VertexShader& vs, FragmentShader&& frag) : sphere_instr(make_sphere.Instructions()) , sphere_indices(make_sphere.Indices()) , fs(std::forward<FragmentShader>(frag)) { // attach the shaders to the program prog.AttachShader(vs); prog.AttachShader(fs); // link and use it prog.Link(); prog.Use(); projection_matrix = (prog/"ProjectionMatrix"); camera_matrix = (prog/"CameraMatrix"); model_matrix = (prog/"ModelMatrix"); light_pos = (prog/"LightPos"); // bind the VAO for the sphere sphere.Bind(); const GLuint n_attr = 2; // pointers to the vertex attribute data build functions typedef GLuint (shapes::Sphere::*Func)(std::vector<GLfloat>&) const; Func func[n_attr] = { &shapes::Sphere::Positions, &shapes::Sphere::Normals, }; // managed references to the VBOs Reference<Buffer> vbo[n_attr] = {verts, normals}; // vertex attribute identifiers from the shaders const GLchar* ident[n_attr] = {"Position", "Normal"}; for(GLuint i=0; i!=n_attr; ++i) { // bind the VBO vbo[i].Bind(Buffer::Target::Array); // make the data std::vector<GLfloat> data; GLuint n_per_vertex = (make_sphere.*func[i])(data); // upload the data Buffer::Data(Buffer::Target::Array, data); // setup the vertex attrib VertexArrayAttrib attr(prog, ident[i]); attr.Setup<GLfloat>(n_per_vertex); attr.Enable(); } }
void QuadPrimitive::setVertices(const VertexArray& arr) { osg::Vec3 vec = { 0.0f, 0.0f, 0.0f }; int i = 0; for ( i = 0; i < arr.size(); i++) { (*m_vertexArray)[i].set(arr[i].getX(),arr[i].getY(),arr[i].getZ()); vec += {arr[i].getX(), arr[i].getY(), arr[i].getZ()}; } m_center = vec / 4.0; m_height = ((*m_vertexArray)[1] - (*m_vertexArray)[0]).length(); m_width = ((*m_vertexArray)[2] - (*m_vertexArray)[1]).length(); m_vertexArray->dirty(); _geometry->dirtyBound(); _outLine->dirtyBound(); }
void prepareWalls() { std::size_t mazeHeight = maze_data.size(); std::size_t mazeWidth = maze_data[0].size(); for (size_t i = 0; i != mazeHeight; ++i) { for (size_t j = 0; j != mazeWidth; ++j) { if (maze_data[i][j] == 'H') { prepareCube(i, j); } } } maze.Ready(); }
TorusExample(void) : make_torus(1.0, 0.5, 36, 24) , torus_instr(make_torus.Instructions()) , torus_indices(make_torus.Indices()) , prog(make_prog()) , projection_matrix(prog, "ProjectionMatrix") , camera_matrix(prog, "CameraMatrix") , model_matrix(prog, "ModelMatrix") { Uniform<Vec4f>(prog, "ClipPlane").Set(0.f, 0.f, 1.f, 0.f); // bind the VAO for the torus torus.Bind(); // bind the VBO for the torus vertices verts.Bind(Buffer::Target::Array); { std::vector<GLfloat> data; GLuint n_per_vertex = make_torus.Positions(data); // upload the data Buffer::Data(Buffer::Target::Array, data); // setup the vertex attribs array for the vertices VertexArrayAttrib attr(prog, "Position"); attr.Setup<GLfloat>(n_per_vertex); attr.Enable(); } // bind the VBO for the torus UV-coordinates texcoords.Bind(Buffer::Target::Array); { std::vector<GLfloat> data; GLuint n_per_vertex = make_torus.TexCoordinates(data); // upload the data Buffer::Data(Buffer::Target::Array, data); // setup the vertex attribs array for the vertices VertexArrayAttrib attr(prog, "TexCoord"); attr.Setup<GLfloat>(n_per_vertex); attr.Enable(); } // gl.ClearColor(0.8f, 0.8f, 0.7f, 0.0f); gl.ClearDepth(1.0f); gl.FrontFace(make_torus.FaceWinding()); gl.Enable(Capability::DepthTest); gl.Enable(Functionality::ClipDistance, 0); }
void Render( const Vec3f& light, const Mat4f& camera, const Mat4f& model ) { // use the shading program prog.Use(); // set the uniforms light_pos.Set(light); camera_matrix.Set(camera); model_matrix.Set(model); // bind the VAO shape.Bind(); // use the instructions to draw the shape // (this basically calls glDrawArrays* or glDrawElements*) shape_instr.Draw(shape_indices); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); // // set the matrix for camera orbiting the origin camera_matrix.Set( CamMatrixf::Orbiting( Vec3f(0.0f, 0.5f, 0.0f), 6.5, Degrees(time * 35), Degrees(55 - SineWave(time / 20.0) * 30) ) ); light_pos.Set(light_path.Position(time / 10.0)); plane.Bind(); plane_instr.Draw(plane_indices); }
unsigned int VertexBuffer::WriteIndices( const VertexArray & va, const unsigned int icount, const unsigned int vcount, std::vector<unsigned int> & index_buffer) { const unsigned int * faces = 0; int fn; va.GetFaces(faces, fn); assert(icount + fn <= index_buffer.size()); unsigned int * ib = &index_buffer[icount]; for (int j = 0; j < fn; ++j) { ib[j] = faces[j] + vcount; } return icount + fn; }
Shape(const Shader& vs, const Shader& fs) : shape_instr(make_shape.Instructions()) , shape_indices(make_shape.Indices()) , prog(make(vs, fs)) , projection_matrix(prog, "ProjectionMatrix") , camera_matrix(prog, "CameraMatrix") , model_matrix(prog, "ModelMatrix") , light_pos(prog, "LightPos") { // bind the VAO for the shape shape.Bind(); const GLuint n_attr = 3; // pointers to the vertex attribute data build functions typedef GLuint (ShapeMaker::*Func)(std::vector<GLfloat>&) const; Func func[n_attr] = { &ShapeMaker::Positions, &ShapeMaker::Normals, &ShapeMaker::TexCoordinates }; // managed references to the VBOs Reference<Buffer> vbo[n_attr] = {verts, normals, texcoords}; // vertex attribute identifiers from the shaders const GLchar* ident[n_attr] = {"Position", "Normal", "TexCoord"}; for(GLuint i=0; i!=n_attr; ++i) { // bind the VBO vbo[i].Bind(Buffer::Target::Array); // make the data std::vector<GLfloat> data; GLuint n_per_vertex = (make_shape.*func[i])(data); // upload the data Buffer::Data(Buffer::Target::Array, data); // setup the vertex attrib VertexArrayAttrib attr(prog, ident[i]); attr.Setup<GLfloat>(n_per_vertex); attr.Enable(); } }
Shape( const Program& prog, const ShapeBuilder& builder ): make_shape(builder) , shape_instr(make_shape.Instructions()) , shape_indices(make_shape.Indices()) , vbos(4) { // bind the VAO for the shape vao.Bind(); typename ShapeBuilder::VertexAttribs vert_attr_info; const GLchar* vert_attr_name[] = { "Position", "Normal", "Tangent", "TexCoord" }; for(int va=0; va!=4; ++va) { const GLchar* name = vert_attr_name[va]; std::vector<GLfloat> data; auto getter = vert_attr_info.VertexAttribGetter(data, name); if(getter != nullptr) try { // bind the VBO for the vertex attribute vbos[va].Bind(Buffer::Target::Array); GLuint npv = getter(make_shape, data); // upload the data Buffer::Data(Buffer::Target::Array, data); // setup the vertex attribs array VertexArrayAttrib attr(prog, name); attr.Setup<GLfloat>(npv); attr.Enable(); } catch(Error&) { } } }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); // Vec3f lightPos(-1.0f, 2.0f, 2.0f); lightPos *= (1.0f - SineWave(time/5.0f)*0.4f); light_pos.Set(lightPos); tex_projection_matrix.Set( CamMatrixf::PerspectiveX(Degrees(15), 1.0, 1, 20) * CamMatrixf::LookingAt(lightPos, Vec3f()) ); // set the model matrix model_matrix.Set( ModelMatrixf::RotationY(FullCircles(time * 0.1)) ); cube.Bind(); gl.CullFace(Face::Front); cube_instr.Draw(cube_indices); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); // CamMatrixf camera = CamMatrixf::Orbiting( Vec3f(), 4.5 - SineWave(time / 16.0) * 1.5, FullCircles(time / 12.0), Degrees(SineWave(time / 30.0) * 90) ); // set the matrix for camera orbiting the origin camera_matrix_3.Set(projection * camera); camera_position_3.Set(camera.Position()); // set the model matrix model_matrix.Set( ModelMatrixf::RotationX(FullCircles(time / 10.0)) ); shape.Bind(); shape_instr.Draw(shape_indices); }
float TextDraw::RenderText( const Font & font, const std::string & text, float x, float y, float scalex, float scaley, VertexArray & output_array) { output_array.Clear(); float cursorx = x; float cursory = y + scaley / 4; for (unsigned int i = 0; i < text.size(); ++i) { if (text[i] == '\n') { cursorx = x; cursory += scaley; } else { cursorx += RenderCharacter(font, text[i], cursorx, cursory, scalex, scaley, output_array); } } return cursorx; }
Shape(const Program& prog, const ShapeBuilder& builder) : make_shape(builder) , shape_instr(make_shape.Instructions()) , shape_indices(make_shape.Indices()) , nva(4) , vbos(nva+1) { vao.Bind(); typename ShapeBuilder::VertexAttribs vert_attr_info; const GLchar* vert_attr_name[] = { "Position", "Normal", "Tangent", "TexCoord" }; for(GLuint va=0; va!=nva; ++va) { const GLchar* name = vert_attr_name[va]; std::vector<GLfloat> data; auto getter = vert_attr_info.VertexAttribGetter(data, name); if(getter != nullptr) try { vbos[va].Bind(Buffer::Target::Array); GLuint npv = getter(make_shape, data); Buffer::Data(Buffer::Target::Array, data); VertexAttribArray attr(prog, name); attr.Setup<GLfloat>(npv); attr.Enable(); } catch(Error& error) { } } vbos[nva].Bind(Buffer::Target::ElementArray); Buffer::Data(Buffer::Target::ElementArray, shape_indices); shape_indices.clear(); }