• Advertisement
Sign in to follow this  

How can i set alpha value to a FBO texture

This topic is 986 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

SOLVED - what an idiot i am i didint check last shader what does it output it happened that

i set FULLSCREEN_SHADER to output 1.0 as alpha :/

 

 

 

I am trying to make a smoke simulation however i am unable to write alpha values to a texture attached to a FBO

 

whatever i write alpha stays 1.0

 

 

heres my code:

inline unsigned int build2DTexFramebuffer(unsigned int texture)
{
	unsigned int framebuffer;
	glGenFramebuffers(1, &framebuffer);
    glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
    return framebuffer;
}

unsigned int blurred_tex; //global var texture
unsigned int blurr_Framebuffer; //global var fbo



glGenTextures(1, &blurred_tex);
		   glBindTexture(GL_TEXTURE_2D, blurred_tex);
		   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
//		   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
//		   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
		 		 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture);



		 		blurr_Framebuffer = build2DTexFramebuffer(blurred_tex);

now i try to bind fbo and clear it with some alpha values then i unbind fbo and draw fullscreen quad on the final scene with blending enabled (texture should blend with background image - well it blend untill i set glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); then texture appears fully opaque

DrawTheScene();

glActiveTexture(GL_TEXTURE0);
glBindFramebuffer(GL_FRAMEBUFFER, blurr_Framebuffer);

glViewport(0,0,128,128);
glClearColor(0.0, 1.0, 0.0, 0.5);
glClear(GL_DEPTH_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT);

//no matter if i try here to render a quad that has alpha 0.0 or whatever i draw or dont drawa anythign ata ll result the same
glBindFramebuffer(GL_FRAMEBUFFER, 0);






//now draw that texture to cover whole screen

glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);

glViewport(0,0, SCREEN_WIDTH, SCREEN_HEIGHT);

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, blurred_tex);
FULLSCREEN_SHADER->Enable();
FULLSCREEN_SHADER->Send1I(glGetUniformLocation(FULLSCREEN_SHADER->gProgram,"output_tex"),0);

glEnable(GL_BLEND);

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

test_cloud->DrawFullScreenQuad(FULLSCREEN_SHADER);
glDisable(GL_BLEND);
FULLSCREEN_SHADER->Disable();


glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST);

:/

Edited by WiredCat

Share this post


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

  • Advertisement