Created
April 15, 2015 13:42
-
-
Save sasekazu/48bec32ad11b3a7b3dad to your computer and use it in GitHub Desktop.
oglplusのミニマムコード modified official example "standalone/001_triangle_glut_glew.cpp"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <GL/glew.h> | |
#include <GL/glut.h> | |
#include <oglplus/all.hpp> | |
oglplus::Context* gl; | |
void Display(void); | |
int main(int argc, char* argv[]){ | |
glutInit(&argc, argv); | |
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); | |
glutInitWindowSize(800, 600); | |
glutInitWindowPosition(100, 100); | |
glutCreateWindow("OGLplus+GLUT+GLEW"); | |
if(glewInit() == GLEW_OK){ | |
// Get OpenGL Context. | |
// This should be put AFTER glewInit(). | |
gl = new oglplus::Context(); | |
// Compile vertex shader | |
oglplus::VertexShader vs; | |
vs.Source( | |
"#version 330\n" | |
"in vec3 Position;" | |
"void main(void){" | |
"gl_Position = vec4(Position, 1.0);" | |
"}" | |
); | |
vs.Compile(); | |
// Compile fragment shader | |
oglplus::FragmentShader fs; | |
fs.Source( | |
"#version 330\n" | |
"out vec4 fragColor;" | |
" void main(void){" | |
"fragColor = vec4(1.0, 0.0, 0.0, 1.0);" | |
"}" | |
); | |
fs.Compile(); | |
// Generate shader program object | |
oglplus::Program prog; | |
prog.AttachShader(vs); | |
prog.AttachShader(fs); | |
prog.Link(); | |
prog.Use(); | |
// VAO | |
oglplus::VertexArray triangle; | |
triangle.Bind(); | |
// VBO | |
oglplus::Buffer verts; | |
verts.Bind(oglplus::Buffer::Target::Array); | |
GLfloat triangle_verts[9] = { | |
0.0f, 0.0f, 0.0f, | |
1.0f, 0.0f, 0.0f, | |
0.0f, 1.0f, 0.0f | |
}; | |
oglplus::Buffer::Data( | |
oglplus::Buffer::Target::Array, | |
9, | |
triangle_verts | |
); | |
oglplus::VertexArrayAttrib vert_attr(prog, "Position"); | |
vert_attr.Setup<GLfloat>(3); | |
vert_attr.Enable(); | |
gl->ClearColor(0.0f, 0.0f, 0.0f, 0.0f); | |
gl->ClearDepth(1.0f); | |
glutDisplayFunc(Display); | |
glutMainLoop(); | |
return 0; | |
} | |
return 1; | |
} | |
void Display(void){ | |
gl->Clear().ColorBuffer().DepthBuffer(); | |
gl->DrawArrays(oglplus::PrimitiveType::Triangles, 0, 3); | |
glutSwapBuffers(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment