i’m currently trying to create some kind of Raytracing with OptiX and OpenGL.
My problem right now is, that i’m trying to bind the texture output from Optix to my OpenGL sphere. After doing some research about binding textures to OpenGL i only found ways to bind an image to the texture.
Although i tried to implement it in a similar way, but i doesn’t work. Any idea which way is the right to do it?
Here my code:
renderOptix.cpp
//global varibles as ids
GLUint optix_tex;
GLuint vbo = 0;
//creating a buffer for optix and binding it to openGL buffer
optix::Buffer CreateOutputOptix(RTformat format, unsigned int width, unsigned int height)
{
optix::Buffer buffer;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
size_t element_size;
optix_context->checkError(rtuGetSizeForRTformat(format, &element_size));
glBufferData(GL_ARRAY_BUFFER, element_size * width * height, 0, GL_STREAM_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
buffer = optix_context->createBufferFromGLBO(RT_BUFFER_OUTPUT, vbo);
buffer->setFormat(format);
buffer->setSize(width, height);
return buffer;
}
optix::Buffer renderInitializeOptix()
{
//initializing the optix context
//set up geometry
createGeometry();
// Create an output texture for OpenGL
glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &optix_tex);
glBindTexture(GL_TEXTURE_2D, optix_tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_BGR, GL_UNSIGNED_BYTE,NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Change these to GL_LINEAR for super- or sub-sampling
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // GL_CLAMP_TO_EDGE for linear filtering, not relevant for nearest.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// glBindTexture(GL_TEXTURE_2D, 0);
}
//function called in the mainloop
void renderOptix()
{
//updating optix context
// Transfer output to OpenGL texture
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, optix_tex);
}
//openGL specific code to bind,probably not necessary again
void renderSetupOptixGL()
{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, optix_tex);
}
main.cpp
//creating sphere
void OpenGLRenderer::RenderSceneGl()
{
glDisable( GL_LIGHTING );
GLUquadricObj *sphere = NULL;
sphere = gluNewQuadric();
gluQuadricDrawStyle(sphere, GLU_FILL);
gluQuadricTexture(sphere, GLU_TRUE);
gluQuadricNormals(sphere, GLU_SMOOTH);
//Making a display list
int mysphereID = glGenLists(1);
glNewList(mysphereID, GL_COMPILE_AND_EXECUTE);
gluSphere(sphere, 1.0, 20, 20);
glEndList();
gluDeleteQuadric(sphere);
}
bool OpenGLRenderer::Do()
{
RenderSceneGl();
renderSetupOptixGL();
renderOptix();
}
if you need further information, just ask Thank you