-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cxx
89 lines (68 loc) · 1.81 KB
/
main.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <stdio.h>
/**
* Draw a Triangle on OSX 10.15.4 ( Catalina )
* Code was originally from:
* http://www.opengl-tutorial.org/beginners-tutorials/tutorial-2-the-first-triangle/
*/
int main ( void ) {
glfwWindowHint( GLFW_SAMPLES, 4 );
glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, 3 );
glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 3 );
glfwWindowHint( GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE );
glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );
GLFWwindow *window;
if ( !glfwInit() ) {
return -1;
}
window = glfwCreateWindow( 640, 480, "Jupiter", NULL, NULL );
if ( !window ) {
glfwTerminate();
return -1;
}
glfwMakeContextCurrent( window );
glewExperimental = true; // Needed in core profile
if ( glewInit() != GLEW_OK ) {
fprintf( stderr, "Failed to initialize GLEW\n" );
return -1;
}
/**
* VAO
*/
GLuint VertexArrayID;
glGenVertexArrays( 1, &VertexArrayID );
glBindVertexArray( VertexArrayID );
// An array of 3 vectors which represents 3 vertices
static const GLfloat g_vertex_buffer_data[] = {
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
};
GLuint vertexbuffer;
glGenBuffers( 1, &vertexbuffer );
glBindBuffer( GL_ARRAY_BUFFER, vertexbuffer );
glBufferData( GL_ARRAY_BUFFER, sizeof( g_vertex_buffer_data ), g_vertex_buffer_data, GL_STATIC_DRAW );
/**
* Loop Until window's context current
*/
while ( !glfwWindowShouldClose( window ) ) {
glClear( GL_COLOR_BUFFER_BIT );
glEnableVertexAttribArray( 0 );
glVertexAttribPointer(
0,
3,
GL_FLOAT,
GL_FALSE,
0,
( void* )0
);
glClearColor( 0.5f, 0.4f, 0.3f, 0.2f );
glDrawArrays( GL_TRIANGLES, 0, 3 );
glDisableVertexAttribArray( 0 );
glfwSwapBuffers( window );
glfwPollEvents();
}
glfwTerminate();
return 0;
}