Sign in to follow this  
Nitish Tripathi

Everything goes black after disabling shaders!

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
V-man    813
Don't worry about fixed function. glUseProgram(0) as you call it.

it is dead and old. Everything should be rendered with shaders.

Share this post


Link to post
Share on other sites
slicer4ever    6760
[quote name='Nitish Tripathi' timestamp='1329465990' post='4913835']
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!
[/quote]

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.

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