Everything goes black after disabling shaders!

Started by
4 comments, last by slicer4ever 12 years, 2 months ago
Hi!

I was wondering if anyone could tell me why after disabling shaders and using the default ones ( glUseProgram(0) ) in the draw loop, anything that I draw gets drawn with color set as black. Even after I specify the color values as non black. Is there a way to make this not happen?

Thanks in advance!
Advertisement
show some code please, a minimalist example if possible.
Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.
Hi!

I got it to work! Turns out, one needs to create a new shader program and use that when rendering text; using the default shaders (glUseProgram(0)) will only give black color to the pixels no matter which color one specifies. smile.png
Oh, by the way, the following was my code, can you tell me whether what I conjectured above is indeed right or did I goof up while attaching the default shaders, or something?


void RenderString(float x, float y, void *font, char* string, int length, float RGB[3]) //My textRenderer
{
char *c;
glRasterPos2f(x, y);
glColor3f(RGB[0], RGB[1], RGB[2]);
glutBitmapString(font, (const unsigned char *)string);
}


void display (void) { //My Draw Loop

glUseProgram (ShaderProgram);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

gluLookAt (R*cos(K)*sin(theta), R*cos(K)*cos(theta), R*sin(K), 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);

glPolygonMode(GL_FRONT,GL_LINE);
glPolygonMode(GL_BACK,GL_LINE);

glBufferData(GL_ARRAY_BUFFER, sizeof(data64), (const void *)data64, GL_STATIC_DRAW);
glVertexPointer (3, GL_FLOAT, 0, 0);
glDrawArrays (GL_TRIANGLES, 0, 4096);

glUseProgram(0); //Using default shaders

char buffer[300];
int length = sprintf(buffer, "the quick brown fox jumps over the lazy dog");
float RGB[3]={1,0,0};
RenderString(0,0, GLUT_BITMAP_8_BY_13, buffer, length, RGB);

glutSwapBuffers();
}

Thanks!
Don't worry about fixed function. glUseProgram(0) as you call it.

it is dead and old. Everything should be rendered with shaders.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

Oh, by the way, the following was my code, can you tell me whether what I conjectured above is indeed right or did I goof up while attaching the default shaders, or something?


void RenderString(float x, float y, void *font, char* string, int length, float RGB[3]) //My textRenderer
{
char *c;
glRasterPos2f(x, y);
glColor3f(RGB[0], RGB[1], RGB[2]);
glutBitmapString(font, (const unsigned char *)string);
}


void display (void) { //My Draw Loop

glUseProgram (ShaderProgram);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

gluLookAt (R*cos(K)*sin(theta), R*cos(K)*cos(theta), R*sin(K), 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);

glPolygonMode(GL_FRONT,GL_LINE);
glPolygonMode(GL_BACK,GL_LINE);

glBufferData(GL_ARRAY_BUFFER, sizeof(data64), (const void *)data64, GL_STATIC_DRAW);
glVertexPointer (3, GL_FLOAT, 0, 0);
glDrawArrays (GL_TRIANGLES, 0, 4096);

glUseProgram(0); //Using default shaders

char buffer[300];
int length = sprintf(buffer, "the quick brown fox jumps over the lazy dog");
float RGB[3]={1,0,0};
RenderString(0,0, GLUT_BITMAP_8_BY_13, buffer, length, RGB);

glutSwapBuffers();
}

Thanks!


this:
glBufferData(GL_ARRAY_BUFFER, sizeof(data64), (const void *)data64, GL_STATIC_DRAW);
should be done in the initialization routine.
and only bind the buffer before calling glVertexPointer/glDrawArrays.

also, unbind the buffer before moving on to draw the string.

this is directly why your drawing strings doesn't work with the default pipeline(interestingly enough, i'm surprised it works when you specify another shader.), looking at the source of glutStringDraw, the reason it doesn't draw anything, is because you still have the other buffer bound, so, when it tries to specify it's own vertice's pointer, it's offsetting into an area of the currently bound buffer that doesn't exist.

@V-Man, yes, everything is going towards the way of the shader, but that doesn't mean anyone should stop using the fixed pipeline. simplistic applications don't require the overhead of understanding how shaders work, and forcing new users to learn also how to interact with the vertex/pixel pipeline as well is only going to alienate user's who wish to learn the basic's of 3D programming.
Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

This topic is closed to new replies.

Advertisement