PDA

View Full Version : Fragment shader appears to be writing all 1's



elchuppa
08-18-2003, 03:45 PM
I am having a little trouble getting my values to output correctly. For some reason my output is all white regardless of the fragment shader code. If I do a readpixels I get (1.0, 1.0, 1.0, 1.0) for each pixel.

my fragment shader looks like this:
(I know it doesn't do much but it's only to see if it's writing correctly.)
void shader(in float2 texCoord: TEXCOORD0,
out float4 color : COLOR)
{
color.r = 1.0f;
color.g = 0.0f;
color.b = 0.0f;
color.a = 0.0f;
}

Theoretically this output should be all red right? But for some reason it is white.

I am not getting any Cg errors or OpenGL errors. I have a valid context, profile, program, etc. My draw function looks like this:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear screen and depth buffer
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

bool drawError(false), readError(false);

const unsigned char *cgExt;
cgExt = glGetString(GL_EXTENSIONS);
fprintf(stderr, "%s\n", cgExt);


cgGLEnableProfile(fragmentProfile);
cgErrorCallback();

cgGLBindProgram(fragmentProgram);
cgErrorCallback();

cgGLEnableTextureParameter(baseTexture);
cgErrorCallback();

glPushMatrix();
//glColor3f(1.0, 0.0, 0.0);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2f(0, 0);
glTexCoord2f(float(size), 0); glVertex2f(float(size), 0);
glTexCoord2f(float(size), float(size)); glVertex2f(float(size), float(size));
glTexCoord2f(0, float(size)); glVertex2f(0, float(size));
glEnd();
glPopMatrix();
if(PrintGLerror())
drawError = true;

glReadPixels(0,0, size, size, GL_RGBA, GL_FLOAT, dataOut);
if(PrintGLerror())
readError = true;

cgGLDisableProfile(fragmentProfile);
cgGLDisableTextureParameter(baseTexture);

SwapBuffers(hDC);

if I uncomment the glColor3f and comment out fragment stuff I get correct rendering of a red quad. I have written fragment shaders successfully before and it's hard for me to see the difference with what I have here and what has worked in the past.
Any help would be greatly appreciated.
thanks.

vincoof
08-19-2003, 11:10 AM
Have you changed your hardware ? If you were using NV hardware and now ATI, that would explain many surprises.

elchuppa
08-19-2003, 11:25 AM
Afraid not. I am running this on an fx5200. http://www.opengl.org/discussion_boards/ubb/frown.gif This is the second rewrite to get around this problem, but so far it has failed. I'm pretty stumped.

elchuppa
08-19-2003, 04:57 PM
I fixed it. The shader.cg file that I had in my VC++ project was actually sitting in a different directory. All the changes I was making to it were irrelevant as an older version of the file that was in the project directory was always left untouched.

doh...
At least that's over.
thanks anyway.