🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.graphics.api.opengl
Article #73

Re: Gamma & color blending

#73
From: Mike Stroyan
Date: Tue, 25 Nov 1997 00:00
56 lines
2724 bytes
Michael Harrison (see@my.sig) wrote:
|On Tue, 18 Nov 1997 11:23:53 -0600, Steve Baker <sbaker@link.com>
|wrote:

|>Gamma correction is not an issue for OpenGL - it's a function of
|>your windowing system. The problem is that OpenGL only operates
|>in the domain of a single window - and Gamma correction must be
|>applied to the entire screen (with most existing hardware
|>implementations).

|Unfortunately I live in the realm where most users don't understand
|this or just can't change the gamma on their systems.  Because of this
|I need a gamma control (really just a brightness control) in my
|program so they can lighten what may be a dark image on their system.

|If I can't affect the gamma (brightness) of the final output with I'll
|just have to live with that.

  You could try a horrible hack and remap the colors in the color buffer
after rendering each frame.  That would be limited by the precision of
the color buffer.  A 16 bit color buffer could produce some big jumps in
brightness.  And then there is the question of performance remapping an
entire viewport of pixels.  In any case, here is an outline for how to
request a gamma remapping for an already rendered image.

#include <math.h>
remap(float gamma_value)
{
    int i;
#   define LEVELS 256
    float gamma_ramp[LEVELS];
    double value;
    double value_step = 1.0/(LEVELS-1.0);
    GLint window[4];

    value = 0.0;
    for (i=0; i<LEVELS; i++) {
        gamma_ramp[i] = pow(value, 1.0/gamma_value);
        value += value_step;
    }
    glPixelMapfv(GL_PIXEL_MAP_R_TO_R, 256, gamma_ramp);
    glPixelMapfv(GL_PIXEL_MAP_G_TO_G, 256, gamma_ramp);
    glPixelMapfv(GL_PIXEL_MAP_B_TO_B, 256, gamma_ramp);
    glPixelTransferi(GL_MAP_COLOR, GL_TRUE);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0, 1.0, 0.0, 1.0);
    glRasterPos2f(0.0, 0.0);
    glGetIntegerv(GL_VIEWPORT, window);
    glCopyPixels(window[0], window[1], window[2], window[3], GL_COLOR);
}

--
Mike Stroyan, mike_stroyan@fc.hp.com
Technical Details
Message-ID: <65fja7$pd3@fcnews.fc.hp.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <64q9ai$66o$1@gte1.gte.net> <890D05DEBDDB08B8.981B135BEAAA47C8.415D6C2C9FAF35B7@library-proxy.airnews.net> <64t97p$eih$1@gte1.gte.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 100291,344bb75021d541c6
X-Google-Attributes: gid100291,public
X-Google-Thread: f65bb,344bb75021d541c6
X-Google-Attributes: gidf65bb,public
From: stroyan@fc.hp.com (Mike Stroyan)
Subject: Re: Gamma & color blending
Date: 1997/11/25
Message-ID: <65fja7$pd3@fcnews.fc.hp.com>
X-Deja-AN: 292659619
References: <64q9ai$66o$1@gte1.gte.net> <890D05DEBDDB08B8.981B135BEAAA47C8.415D6C2C9FAF35B7@library-proxy.airnews.net> <64t97p$eih$1@gte1.gte.net>
Followup-To: comp.graphics.api.opengl,3dfx.opengl
Organization: Hewlett-Packard Fort Collins Site
Newsgroups: comp.graphics.api.opengl,3dfx.opengl