-
Notifications
You must be signed in to change notification settings - Fork 0
/
point.cpp
76 lines (65 loc) · 1.49 KB
/
point.cpp
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
#include <GL/glew.h>
#include <GL/freeglut.h>
#include <stdio.h>
GLuint VBO;
struct Vector3f
{
float x;
float y;
float z;
Vector3f() {}
Vector3f(float _x, float _y, float _z)
{
x = _x;
y = _y;
z = _z;
}
};
static void RenderSceneCB()
{
glClear(GL_COLOR_BUFFER_BIT);
glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glVertexPointer(3,GL_FLOAT,0,NULL);
glDrawArrays(GL_POINTS,0,1);
glDisableClientState(GL_VERTEX_ARRAY);
glutSwapBuffers();
}
static void InitializeGlutCallbacks()
{
glutDisplayFunc(&RenderSceneCB);
}
static void CreateVertexBuffer()
{
Vector3f vertices[3];
vertices[0] = Vector3f(-0.9f, -0.9f, 0.0f);
vertices[1] = Vector3f(1.0f, -1.0f, 0.0f);
vertices[2] = Vector3f(0.0f, 1.0f, 0.0f);
/*
vertices[0] = Vector3f(0.6f, 0.6f, 0.0f);
vertices[1] = Vector3f(0.2f, 0.2f, 0.0f);
vertices[2] = Vector3f(0.3f, 0.3f, 0.0f);
*/
glGenBuffers(1,&VBO);
glBindBuffer(GL_ARRAY_BUFFER,VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
}
int
main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
glutInitWindowSize(800,600);
glutInitWindowPosition(100,100);
glutCreateWindow("create window");
InitializeGlutCallbacks();
GLenum res = glewInit();
if(res != GLEW_OK) {
fprintf(stderr, "Error: %s\n", glewGetErrorString(res));
return 1;
}
glClearColor(0.0f,0.0f,0.3f,0.0f);
CreateVertexBuffer();
glutMainLoop();
return 0;
}