Jump to content
  • Advertisement
Sign in to follow this  
Nitish Tripathi

Everything goes black after disabling shaders!

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

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
Advertisement
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

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
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

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.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!