Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

This draws a white vertical line from 640 to 768 at x512:

glDisable(GL_TEXTURE_2D);
glBegin(GL_LINES);
      glColor3f((double)R/255,(double)G/255,(double)B/255);
      glVertex3f(SX, -SPosY, 0); // origin of the line
      glVertex3f(SX, -EPosY, 0); // ending point of the line
glEnd();
glEnable(GL_TEXTURE_2D);

This works, but after having a problem where it wouldn't draw it white (Or to any colour passed) I discovered that disabling GL_TEXTURE_2D Before drawing the line, and the re-enabling it afterwards for other things, fixed it. I want to know, is this a normal step a programmer might take? Or is it highly inefficient? I don't want to be causing any slow downs due to a mistake =)

Thanks

share|improve this question
    
Are you binding a texture somewhere else in your code? Maybe the texture isn't being unbound, and then gets applied to the lines. –  loganfsmyth Mar 25 '12 at 3:11
    
Yep I am! Thanks. I was actually binding it in the Sprite Create function I had. Does this mean I should bind it, draw the textured quad and then unbind it? Then ofcourse the Line function should work =) Oh and yep that fixed it: glBindTexture(GL_TEXTURE_2D, NULL); –  Aaron Mar 25 '12 at 3:24
add comment

1 Answer 1

Yes, this is extremely common. A major problem a lot of people face is an unbound texture being applied to a line accidentally, or having GL_TEXTURE_2D enabled, but without a texture, in which case the line is always drawn black (no texture = black = 0, (black(0) * given color = black(0))

There is nothing inefficient as such with your code, though it is usually a wise choice to try to avoid switching unnecessarily. (eg. if you were to have to draw another line as well, don't constantly enable/disable, instead do it all in between one disable and enable).

Hope this helped.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.