Jump to content
  • Advertisement
Sign in to follow this  
w17chm4n

OpenGL [GLSL] Problem with texturing

This topic is 3182 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi ! I`m working on a simple ray tracer based on glsl and i`ve bumped on little, irritating problem - when I bind my output texture, which holds ray traced image to a fullscreen aligned quad, the result I get is that the whole screen is in some color instead of the image. The textures in memory looks like this: buffers And the image I see in window looks like this: window I`m using VBO for drawing fullscreen aligned quad and this works for sure. Here is my code for creating texture and binding it to FBO: -----------------------------------------------------------
glGenTextures(1, &m_TEXTURE_OUTPUT);
glBindTexture(GL_TEXTURE_2D, m_TEXTURE_OUTPUT);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, m_windowWidth, m_windowHeight, 0, GL_BGRA, GL_FLOAT, m_outputData);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);


glGenFramebuffersEXT(1, &m_fbo0);
		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo0);
		glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT5_EXT, GL_TEXTURE_2D, m_TEXTURE_OUTPUT, 0);


And here is the code for rendering single frame: ------------------------------------------------
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_instance->m_fbo0);

		if(m_instance->m_flag)
		{
			m_instance->m_bfRayGeneratorKernel->execute();
			m_instance->m_flag = false;
		}		

		for(unsigned int i = 0; i <= m_instance->m_world->m_triangles.size(); ++i)
		{
			m_instance->m_bfRayTraceKernel->execute();
			m_instance->m_bfCopyKernel2->execute();
		}

		m_instance->m_bfShadingKernel->execute();
		m_instance->m_bfCopyKernel1->execute();
		
		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

		//-------- RENDER TO SCREEN --------//

		glClearColor(0.f, 0.f, 0.f, 0.f);
		glClear(GL_COLOR_BUFFER_BIT);

		glEnable(GL_TEXTURE_2D);

		glBindTexture(GL_TEXTURE_2D, m_instance->m_TEXTURE_OUTPUT);

		m_instance->m_streamGenerator->screenAlignedQuadVBO();

		glDisable(GL_TEXTURE_2D);

		//----------------------------------//

		glFinish();
		glutSwapBuffers();
		glutPostRedisplay();


So, are there any ideas why I can`t display the correct texture in application window ? Could be it the fact, that output texture is filled with FLOAT values and OpenGL cannot automaticly map this to int values from <0; 255> range ? [Edited by - w17chm4n on March 2, 2010 1:15:28 PM]

Share this post


Link to post
Share on other sites
Advertisement
Hmm after some debugging I found, that running two different shaders while rendering frame causes that I cannot even display properly a vertex data texture.

For example when my code does something like that:

shader1
shader1
bind vertexData
drawFullScreenAlignedQuad


Verex data texture displays properly. But when I try to do this

shader1
shader2
bind vertexData
drawFullScreenAlignedQuad


Displayed image is and full screen aligned quad, but in one color istead of showing vertex data texture as above.

To make this clear, I post my code used for running shaders


m_bfRayGeneratorKernel = new GLGPU::BruteForceRayGeneratorKernel(m_streamGenerator, m_camera, m_world);
m_bfRayGeneratorKernel->loadShader("shaders/ray_generator");
m_bfRayGeneratorKernel->addOutput(m_texture2attachment[m_TEXTURE_RAYDIR]);

glGenFramebuffersEXT(1, &m_fbo0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT6_EXT, GL_TEXTURE_2D, m_TEXTURE_RAYDIR, 0);

m_texture2attachment[m_TEXTURE_RAYDIR] = GL_COLOR_ATTACHMENT6_EXT;

//---------------------------------- SHADER EXECUTION ---------------------

glUseProgram(m_program);

for(unsigned int i = 0; i < m_inputTextures.size(); i++)
{
glActiveTexture(GL_TEXTURE0 + i);
glBindTexture(GL_TEXTURE_2D, m_inputTextures);
setUniform1i(m_inputNames, i);
}

if(m_outputTextures.size() > 0)
{
glDrawBuffers(m_outputTextures.size(), m_buffers);
}

update();

m_streamGenerator->screenAlignedQuadVBO();

glUseProgram(0);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!