void TMesh::CreateFace( const TVector3& Coord1, const TVector3& Coord2, const TVector3& Coord3) { Release(); try { Allocate(3, 1); // Vertices m_Vertices[0].m_Coords = Coord1; m_Vertices[1].m_Coords = Coord2; m_Vertices[2].m_Coords = Coord3; // Faces m_Faces[0].Set(0, 1, 2); // Processing ReevaluateBounds(); AverageNormals (); } catch(...) { Release(true); throw 1; } }
void TMesh::CreateFlatGrid( const FPOINT& Corner1, const FPOINT& Corner2, size_t szNXSegs, size_t szNYSegs) { Release(); try { DEBUG_VERIFY(szNXSegs > 0 && szNYSegs > 0); Allocate((szNXSegs + 1) * (szNYSegs + 1), (szNXSegs * szNYSegs) << 1); size_t x, y; // Vertices float yc = BOUNDC(0, szNYSegs, Corner1.y, Corner2.y); float xc = BOUNDC(0, szNXSegs, Corner1.x, Corner2.x); TVertex* pVertex = m_Vertices.GetDataPtr(); for(y=0 ; y<=szNXSegs ; y++) { float cy = BOUNDR(y, 0, Corner1.y, yc); for(x=0 ; x<=szNXSegs ; x++) { float cx = BOUNDR(x, 0, Corner1.x, xc); pVertex->m_Coords.Set(cx, cy, 0.0f); pVertex++; } } // Faces TFace* pFace = m_Faces.GetDataPtr(); for(y=0 ; y<szNYSegs ; y++) { size_t szIndex = y * (szNXSegs + 1); for(x=0 ; x<szNXSegs ; x++, szIndex++) { pFace++->Set(szIndex, szIndex + 1, szIndex + szNXSegs + 1); pFace++->Set(szIndex + 1, szIndex + szNXSegs + 1, szIndex + szNXSegs + 2); } } // Processing ReevaluateBounds(); AverageNormals (); } catch(...) { Release(true); throw 1; } }
void CreateVBO(void) { CreateModel(); AverageNormals(); glGenVertexArrays(1, &VaoId); glBindVertexArray(VaoId); glGenBuffers(1, &VboId); glBindBuffer(GL_ARRAY_BUFFER, VboId); glBufferData(GL_ARRAY_BUFFER, sizeof(points) + sizeof(normals), NULL, GL_STATIC_DRAW); glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(points), points); glBufferSubData(GL_ARRAY_BUFFER, sizeof(points), sizeof(normals),normals); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0)); //glGenBuffers(1, &NormalBufferId); //glBindBuffer(GL_ARRAY_BUFFER, NormalBufferId); //glBufferData(GL_ARRAY_BUFFER, sizeof(normals), normals, GL_STATIC_DRAW); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(sizeof(points))); }