#include<iostream>
#include"sf_display.h"#include"sf_mesh.h"int main(int argc, char** argv){SF_Display Display(1280, 720, "Viewport");static const GLfloat triangle[] = { 0.0f, 0.5f, 0.0f, 0.5f, -0.5f, 0.0f, -0.5f, -0.5f, 0.0f };SF_Mesh Mesh(triangle);while (Display.SF_IsClosed()){Display.SF_Clear(0.0f, 0.1f, 0.3f, 1.0f);Mesh.SF_Draw();Display.SF_Update();}return 0;}
sf_mesh.cpp
#include "sf_mesh.h"
SF_Mesh::SF_Mesh(static const GLfloat data[]){glGenVertexArrays(1, &sf_vertexArrayID);glBindVertexArray(sf_vertexArrayID);glGenBuffers(1, &sf_vertexBuffer);glBindBuffer(GL_ARRAY_BUFFER, sf_vertexBuffer);glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);glEnableVertexAttribArray(0);glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);glBindVertexArray(0);}SF_Mesh::~SF_Mesh(){glDeleteVertexArrays(1, &sf_vertexArrayID);}void SF_Mesh::SF_Draw(){glBindVertexArray(sf_vertexArrayID);glDrawArrays(GL_TRIANGLES, 0, 3);glBindVertexArray(0);}
sf_mesh.h
#ifndef SF_MESH_H
#define SF_MESH_H#include"sf_ogl_includes.h"class SF_Mesh{public:SF_Mesh(static const GLfloat data[]);void SF_Draw();~SF_Mesh();private:GLuint sf_vertexBuffer;GLuint sf_vertexArrayID;};#endif