Reanimation
Reanimation

Reputation: 3336

OpenGL 'reshape()' function Viewport Border Background

I've created a window using Win32 in an OpenGL 3.2+ program and I'm experimenting with things. Currently I'm using the reshape() function below to resize the window etc.

I've added a border within the viewport so it leaves a 50px border around the viewport which does what I was expecting.

    void reshape(int width, int height, int pers_Dist)
    {
      screenWidth = width;
      screenHeight = height;
      float border = 50;

      glViewport(0+border,0+border,width-(border*2),height-(border*2));

      MatrixRoutines<float>::perspective(pers_Dist, (GLfloat)screenWidth/(GLfloat)screenHeight, 1, 200, ProjectionMatrix);
    }

The background colour is set inside the init() function using: glClearColor(0.0,0.0,0.0,0.0);, to black.

My question is, can the border be assigned a different colour to the background? (if I change the colour, both the background and border are always the colour set).

Upvotes: 1

Views: 999

Answers (1)

genpfault
genpfault

Reputation: 52084

Use scissor regions to tell OpenGL where to clear:

  1. glDisable( GL_SCISSOR_TEST )
  2. Clear with border color
  3. Set scissor to border region
  4. glEnable( GL_SCISSOR_TEST )
  5. Clear with inner color
  6. Render scene

Upvotes: 1

Related Questions