Sign in to follow this  
ade-the-heat

OpenGL UPDATED ! pls read again can't get the simplest shader working

Recommended Posts

I'm using texture rectangles and doing GPGPU (not that makes much difference). The shader I'm doing is so simple that I can't see why it's not working. All i want to do is to set each rgba value to a number I pass in. In this case = 2.0f. All I do is set viewport, enable shader, pass in param, draw quad, get back data
//SET UP VIEWPORT
glEnable(iTextureType);
glViewport(0, 0, itexSizeW, itexSizeH);
glMatrixMode(GL_PROJECTION);    
glLoadIdentity();               
gluOrtho2D(0.0, itexSizeW, 0.0, itexSizeH);
glMatrixMode(GL_MODELVIEW);     
glLoadIdentity(); 

//ENABLE SHADER
glUseProgram(m_shaders[shaderHandle].program);
//set uniforms
GLint location = fglGetUniformLocation(m_shaders[shaderHandle].program,"value");
fglUniform1f(location, 0.5f);
//DRAW A QUAD
// make quad filled to hit every pixel/texel
glPolygonMode(GL_FRONT,GL_FILL);
// and render quad
glBegin(GL_QUADS);
    glTexCoord2f(0.0, 0.0); 
    glVertex2f(0.0, 0.0);
    glTexCoord2f(itexSizeW, 0.0); 
    glVertex2f(itexSizeW, 0.0);
    glTexCoord2f(itexSizeW, itexSizeH); 
    glVertex2f(itexSizeW, itexSizeH);
    glTexCoord2f(0.0, itexSizeH); 
    glVertex2f(0.0, itexSizeH);
glEnd();

//GET DATA BACK
glBindTexture(iTextureType, mTextures[TEX_TMP2]);
float *textureData = (float*)malloc( ((int)mVoxelFaceCount*4)*sizeof(float) );
//copy frame
glCopyTexSubImage2D(iTextureType, 0, 0, 0, 0, 0, itexSizeW, itexSizeH);
glGetTexImage(iTextureType, 0, GL_RGBA, GL_FLOAT,  (void*)textureData );
CHECK_OPENGL_ERR;

float data;
for (unsigned int i=0; i<mVoxelFaceCount; i++)
{
     data=textureData[i];  //everything is junk !!!
}

free(textureData);
CHECK_OPENGL_ERR;



The shade itself is just:
uniform float value;
void main (void)
{
	gl_FragColor = vec4(value);
}




[Edited by - ade-the-heat on May 23, 2007 7:20:20 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this