render a raytraced scene in opengl

Started by
6 comments, last by PlutoWarrior 16 years, 3 months ago
Hey guys, So I've just finished writing up some code to make a basic ray tracer. It handles all vectors and ray casts and can do all the things I need to do to calculate lighting and reflections in my scene. Now I want to render all the wonderful math into a beautiful scene but I dunno what the best way to go about doing this in OpenGL. I'm open to suggestions!
---------------------------------------------Warning: This post may contain traces of Q-Basic
Advertisement
I guess the only thing left to do is give the buffer to GL. You can use glDrawPixels to draw it to a GL surface. GOogle it to see code examples
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
hey

I think it might be best to just copy into a texture, and render the texture on a quad to the screen or something. Well it's just that I've heard glDrawPixels() is slow or something? although I have no clue about this myself, as I've never looked into it :\.

Checkout glTexSubImage2D() for updating part of, or all of the texture data.

Hmm, or maybe you can use a Pixel Buffer Object to access and update the texture data directly? but I know quite little about these.

cya
I'll try looking into both methods and see what I can do, maybe I'll post some pictures if I get this working soon.
---------------------------------------------Warning: This post may contain traces of Q-Basic
Quote:Original post by yosh64
hey

I think it might be best to just copy into a texture, and render the texture on a quad to the screen or something. Well it's just that I've heard glDrawPixels() is slow or something? although I have no clue about this myself, as I've never looked into it :\.

Checkout glTexSubImage2D() for updating part of, or all of the texture data.

Hmm, or maybe you can use a Pixel Buffer Object to access and update the texture data directly? but I know quite little about these.

cya


I would do it using textures. Create a map of a given resolution on a texture, from the perspective of each triangle in the scene, then turn it into a texture and render it to that object. The same would work if the only OpenGL polygon in the scene was drawn over the entire screen.

Are you trying to use OGL to display the result of RT or are you trying to integrate RT in a OpenGL rendered scene?
In the first case I would create a full screen quad and use the RT resulting image as a texture. If you are going to build a real time raytracer, consider the possibility to use Pixel Shader to perform some operations too speed them up, like Tone Mapping, Blooms, and other post processing effects.

Check out how the gurus do it:

http://ompf.org/forum/viewtopic.php?f=4&t=657&start=0&st=0&sk=t&sd=a
Thanks everyone, I took what you said into account and I finally got something to the screen. It's not much but at least it's a start. Next step is to add some more features like reflection, refraction, and shadows. I also need to make the algorithm a little more suitable to recursive ray casting cause right now it's pretty hacked together. Here's a look.

Free Image Hosting at www.ImageShack.us
---------------------------------------------Warning: This post may contain traces of Q-Basic

This topic is closed to new replies.

Advertisement