-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRender_gl.cpp
56 lines (48 loc) · 1.31 KB
/
Render_gl.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
//
// Created by liwen on 6/27/18.
//
#include "Render.h"
#include "Render_gl.h"
#include <GLFW/glfw3.h>
#include <iostream>
void Render::openglRender(const Canvas &c) {
GLFWwindow* window;
if (!glfwInit())
return;
window = glfwCreateWindow(c.W, c.H, "Ray tracing demo", NULL, NULL);
if (!window)
{
glfwTerminate();
return;
}
glfwMakeContextCurrent(window);
while (!glfwWindowShouldClose(window)) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
int window_width = c.W;
int window_height = c.H;
glPointSize(1.0);
double dx = 2.0f / window_width;
double dy = 2.0f / window_height;
glBegin(GL_POINTS);
for (long y = 0; y < window_height; ++y) {
double sy = -1 + dy * y;
for (long x = 0; x < window_width; ++x) {
double sx = -1 + dx * x;
Color3 temp_c = c.sample(x, y);
glColor3ub(temp_c.r, temp_c.g, temp_c.b);
glVertex3f(sx, sy, 0);
}
}
glEnd();
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
}
#ifdef GL_ONLY
void Render::opencvRender(const Canvas &c) {
std::cout << "only support openGL rendering\n";
return;
}
#endif