Clearing a previously set color

I’m having a strange issue where I draw a texture and then draw a line afterwards in red. The texture draws fine, and so does the line, but if I redraw again, the texture draws with a shade of red.

(I’m working in Cocoa and am new to OpenGL, although I wrote a small cross-platform Tetris game back in 06 but have since forgotten everything. Currently trying to learn a little more by porting over an old 2D game.)

Here’s the code:

- (void)drawRect:(NSRect)rect
	[[self openGLContext] makeCurrentContext];

	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	if (!bgImg)
		bgImg = [[GLImage alloc] initWithImageNamed:@"background.png"];
	[bgImg drawAtPoint:NSZeroPoint];
	glColor3d(1.0, 0.0, 0.0);
	glVertex3f(0.0f, 0.0f, 0.0f);
	glVertex3f(mouseLoc.x, mouseLoc.y, 0.0f);
	[[self openGLContext] flushBuffer];

- (void)mouseDragged:(NSEvent *)theEvent
	mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
	[self setNeedsDisplay:YES];

GLImage is just a separate class that handles loading and drawing an image.

Ok this seems to fix it, although I’m confused as to why this isn’t causing it to display solid white.

glColor3f(1.0, 1.0, 1.0);

It seems your texture modulates with the color. It must be your texture environment (look at your glTexEnv funcs).

Thanks. I looked into it and using glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); fixes it without having to use glColor3f().