Skip to content

Commit 0451963

Browse files
committed
clickable
1 parent 94631b0 commit 0451963

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

src/main.cpp

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ struct Vertex {
1414
float x, y, z;
1515
};
1616

17-
static std::vector<Vertex> vertices;
17+
static std::vector<Vertex> vertices = {
18+
{0.0f, 0.5f, 0.0f},
19+
{-0.5f, -0.5f, 0.0f},
20+
{0.5f, -0.5f, 0.0f},
21+
};
1822

1923
static void load_obj(std::string path) {
2024
std::ifstream file(path);
@@ -38,6 +42,8 @@ static void load_obj(std::string path) {
3842
}
3943

4044
static void draw_obj() {
45+
CHECK_GL(glPointSize(42.0f));
46+
4147
glBegin(GL_POINTS);
4248

4349
for (auto const &vertex : vertices) {
@@ -47,8 +53,29 @@ static void draw_obj() {
4753
CHECK_GL(glEnd());
4854
}
4955

56+
static void mouse_button_callback
57+
( GLFWwindow *window
58+
, int button
59+
, int action
60+
, int mods
61+
) {
62+
if ( button == GLFW_MOUSE_BUTTON_LEFT
63+
&& action == GLFW_PRESS
64+
) { // when left mouse button is pressed:
65+
double xpos, ypos;
66+
int width, height;
67+
glfwGetCursorPos(window, &xpos, &ypos);
68+
glfwGetWindowSize(window, &width, &height);
69+
70+
float x = (float)(2 * xpos / width - 1);
71+
float y = (float)(2 * (height - ypos) / height - 1);
72+
73+
vertices.push_back(Vertex{x, y, 0});
74+
}
75+
}
76+
5077
static void initialize() {
51-
load_obj("/home/bate/Codes/zeno_assets/assets/monkey.obj");
78+
/* load_obj("/home/bate/Codes/zeno_assets/assets/monkey.obj"); */
5279
CHECK_GL(glEnable(GL_DEPTH_TEST));
5380
}
5481

@@ -116,6 +143,8 @@ int main() {
116143
}
117144
std::cerr << "OpenGL version: " << glGetString(GL_VERSION) << '\n';
118145

146+
glfwSetMouseButtonCallback(window, mouse_button_callback);
147+
119148
initialize();
120149
// start main game loop
121150
while (!glfwWindowShouldClose(window)) {

0 commit comments

Comments
 (0)