-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
508f7fa
commit 40cb193
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include <GL\glew.h> | ||
#include <GL\glut.h> | ||
#include <CL\cl.hpp> | ||
|
||
//#define GL_SHARING_EXTENSION "cl_khr_gl_sharing" | ||
|
||
const int window_width = 1280; | ||
const int window_height = 720; | ||
|
||
// OpenGL vertex buffer object | ||
GLuint vbo; | ||
|
||
void render(); | ||
|
||
void initGL(int argc, char** argv){ | ||
// init GLUT for OpenGL viewport | ||
glutInit(&argc, argv); | ||
// specify the display mode to be RGB and single buffering | ||
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); | ||
// specify the initial window position | ||
glutInitWindowPosition(50, 50); | ||
// specify the initial window size | ||
glutInitWindowSize(window_width, window_height); | ||
// create the window and set title | ||
glutCreateWindow("Basic OpenCL path tracer"); | ||
|
||
// register GLUT callback function to display graphics: | ||
glutDisplayFunc(render); | ||
|
||
// initialise OpenGL extensions | ||
glewInit(); | ||
|
||
// initialise OpenGL | ||
glClearColor(0.0, 0.0, 0.0, 1.0); | ||
glMatrixMode(GL_PROJECTION); | ||
gluOrtho2D(0.0, window_width, 0.0, window_height); | ||
} | ||
|
||
void createVBO(GLuint* vbo) | ||
{ | ||
//create vertex buffer object | ||
glGenBuffers(1, vbo); | ||
glBindBuffer(GL_ARRAY_BUFFER, *vbo); | ||
|
||
//initialise VBO | ||
unsigned int size = window_width * window_height * sizeof(cl_float3); | ||
glBufferData(GL_ARRAY_BUFFER, size, 0, GL_DYNAMIC_DRAW); | ||
glBindBuffer(GL_ARRAY_BUFFER, 0); | ||
} | ||
|
||
void drawGL(){ | ||
|
||
//clear all pixels, then render from the vbo | ||
glClear(GL_COLOR_BUFFER_BIT); | ||
glBindBuffer(GL_ARRAY_BUFFER, vbo); | ||
glVertexPointer(2, GL_FLOAT, 16, 0); // size (2, 3 or 4), type, stride, pointer | ||
glColorPointer(4, GL_UNSIGNED_BYTE, 16, (GLvoid*)8); // size (3 or 4), type, stride, pointer | ||
|
||
glEnableClientState(GL_VERTEX_ARRAY); | ||
glEnableClientState(GL_COLOR_ARRAY); | ||
glDrawArrays(GL_POINTS, 0, window_width * window_height); | ||
glDisableClientState(GL_COLOR_ARRAY); | ||
glDisableClientState(GL_VERTEX_ARRAY); | ||
|
||
// flip backbuffer to screen | ||
glutSwapBuffers(); | ||
} | ||
|
||
void Timer(int value) { | ||
glutPostRedisplay(); | ||
glutTimerFunc(15, Timer, 0); | ||
} |