feature/imgui-sdl
points-test
Last change
on this file since 516668e was 516668e, checked in by Dmitry Portnoy <dmp1488@…>, 7 years ago |
WIP for drawing a triangle
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Rev | Line | |
---|
[5272b6b] | 1 | #include <cstdio>
|
---|
| 2 | #include <iostream>
|
---|
| 3 |
|
---|
| 4 | #include <GL/glew.h>
|
---|
| 5 | #include <GLFW/glfw3.h>
|
---|
| 6 |
|
---|
| 7 | using namespace std;
|
---|
| 8 |
|
---|
| 9 | int main(int argc, char* argv[]) {
|
---|
| 10 | cout << "New OpenGL Game" << endl;
|
---|
| 11 |
|
---|
| 12 | if (!glfwInit()) {
|
---|
| 13 | fprintf(stderr, "ERROR: could not start GLFW3\n");
|
---|
| 14 | return 1;
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | GLFWwindow* window = glfwCreateWindow(640, 480, "Hello Triangle", NULL, NULL);
|
---|
| 18 | if (!window) {
|
---|
| 19 | fprintf(stderr, "ERROR: could not open window with GLFW3\n");
|
---|
| 20 | glfwTerminate();
|
---|
| 21 | return 1;
|
---|
| 22 | }
|
---|
| 23 | glfwMakeContextCurrent (window);
|
---|
| 24 | glewExperimental = GL_TRUE;
|
---|
| 25 | glewInit();
|
---|
| 26 |
|
---|
| 27 | const GLubyte* renderer = glGetString(GL_RENDERER);
|
---|
| 28 | const GLubyte* version = glGetString(GL_VERSION);
|
---|
| 29 | printf("Renderer: %s\n", renderer);
|
---|
| 30 | printf("OpenGL version supported %s\n", version);
|
---|
| 31 | glEnable(GL_DEPTH_TEST);
|
---|
| 32 | glDepthFunc(GL_LESS);
|
---|
[516668e] | 33 |
|
---|
| 34 | GLfloat points[] = {
|
---|
| 35 | 0.0f, 0.5f, 0.0f,
|
---|
| 36 | 0.5f, -0.5f, 0.0f,
|
---|
| 37 | -0.5f, -0.5f, 0.0f,
|
---|
| 38 | };
|
---|
| 39 |
|
---|
| 40 | GLuint vbo = 0;
|
---|
| 41 | glGenBuffers(1, &vbo);
|
---|
| 42 | glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
---|
| 43 | glBufferData(GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW);
|
---|
| 44 |
|
---|
| 45 | GLuint vao=0;
|
---|
| 46 | glGenVertexArrays(1, &vao);
|
---|
| 47 | glBindVertexArray(vao);
|
---|
| 48 | glEnableVertexAttribArray(0);
|
---|
| 49 | glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
---|
| 50 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
|
---|
| 51 |
|
---|
[5272b6b] | 52 | glfwTerminate();
|
---|
| 53 | return 0;
|
---|
| 54 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.