Results 1 to 4 of 4

Thread: How to render gradient background?

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2003
    Posts
    7

    How to render gradient background?

    Dear all,

    I want to render a background with gradient colors, say from green to white, but I don't know how, any hints or suggestions?

    Thanks.

  2. #2
    Junior Member Newbie
    Join Date
    Oct 2003
    Location
    France
    Posts
    1

    Re: How to render gradient background?

    A simple quad, with 2 color parameters, should be enough.
    --
    blaine

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2003
    Posts
    7

    Re: How to render gradient background?

    This works, however this quad rotates as I manipulate the scence with mouse, as is not expected; and also, some of lines I render are not visible after using this code. Any hints?

    [This message has been edited by kangarooxy (edited 10-27-2003).]

  4. #4
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,450

    Re: How to render gradient background?

    The background drawing needs its own modelview projection matrix.
    Disable depth test for the background.

    Easiest code (not tested):
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-1.0, 1.0, -1.0, 1.0, 1.0, -1.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glDisable(GL_DEPTH_TEST); // Color buffer only rendering
    glBegin(GL_QUADS);
    glColor3fv(bottomColor);
    glVertex2f(-1.0f, -1.0f);
    glVertex2f( 1.0f, -1.0f);
    glColor3fv(topColor);
    glVertex2f( 1.0f, 1.0f);
    glVertex2f(-1.0f, 1.0f);
    glEnd();
    ...
    // Put your other code which sets up its own projection and modelview matrices here.
    // Don't forget to clear the depth buffer.

Similar Threads

  1. Gradient background and MFC resize
    By dcr269 in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 02-27-2015, 09:30 AM
  2. Drawing background gradient
    By esapir in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 03-14-2014, 01:03 PM
  3. gradient background?
    By popapez in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-07-2009, 03:01 PM
  4. Gradient background
    By gourou in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 03-27-2008, 02:41 PM
  5. Gradient Background
    By mandyV in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 07-06-2001, 07:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean