Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Clearing a previously set color

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2009
    Posts
    8

    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:
    Code :
    - (void)drawRect:(NSRect)rect
    {
    	[[self openGLContext] makeCurrentContext];
     
    	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    	glLoadIdentity();
     
    	if (!bgImg)
    		bgImg = [[GLImage alloc] initWithImageNamed:@"background.png"];
    	[bgImg drawAtPoint:NSZeroPoint];
     
    	glBegin(GL_LINES);
    	glColor3d(1.0, 0.0, 0.0);
    	glLineWidth(5.0);
    	glVertex3f(0.0f, 0.0f, 0.0f);
    	glVertex3f(mouseLoc.x, mouseLoc.y, 0.0f);
    	glEnd();
     
    	[[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.

  2. #2
    Junior Member Newbie
    Join Date
    Feb 2009
    Posts
    8

    Re: Clearing a previously set color

    Ok this seems to fix it, although I'm confused as to why this isn't causing it to display solid white.
    Code :
    glColor3f(1.0, 1.0, 1.0);

  3. #3
    Intern Newbie
    Join Date
    Jan 2009
    Posts
    41

    Re: Clearing a previously set color

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

  4. #4
    Junior Member Newbie
    Join Date
    Feb 2009
    Posts
    8

    Re: Clearing a previously set color

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •