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: How can i set color to a viewport area?

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2010
    Posts
    20

    Question How can i set color to a viewport area?

    Code :
    #include <stdio.h>
    #include <stdlib.h>
    #include <GL/gl.h>
    #include <GL/glut.h>
     
    #define KEY_ESCAPE 27
     
    void display();
    void keyboard(unsigned char,int,int);
     
    int main(int argc, char **argv) {
        glutInit(&argc, argv);    
        glutInitWindowSize(600,400);
        glutCreateWindow("Opengl Test");
        glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH );
        glutDisplayFunc(display);
        glutKeyboardFunc(keyboard);
        glutMainLoop();
        return 0;
    }
    void display() {
        int i;
        float x,y,z;
        x=0;
        y=0;
        z=0;
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glViewport(0,0,300,400);
        glBegin(GL_POINTS);
        for(i=0;i<50;i++) {
            glColor3f(1,0,1);
            glVertex3f(x,y,z);
            x=x+0.02;
        }
        glEnd();
        glutSwapBuffers();    
    }
    void keyboard(unsigned char key, int x, int y) {
        switch (key) {
            case 27:
            exit (0);
              break;
        }
    }
    I want to set color to viewport. How can i do this?

  2. #2
    Member Regular Contributor
    Join Date
    Jan 2012
    Location
    Germany
    Posts
    325
    Maybe glClearColor is what you want (if not, I didn't understand your question, so please reformulate what you want to do).

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,201
    With a 600x400 window, if you want to colour a portion of it, you could enable scissor test, set a scissor rectangle, then glClear it, remembering to disable scissor test when done. There are other ways available too - such as glDrawPixels from a PBO - but scissor is probably the easiest with the least dependencies.

  4. #4
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    455
    You could limit the area affected by glClear by using glScissor, eg:
    Code :
    glEnable(GL_SCISSOR_TEST);
    glScissor[LEFT][COLOR=#333333](0,0,300,400);[/COLOR][/LEFT]
    alternatively you could draw a quad (maybe with depth testing disabled) to clear a region.

Posting Permissions

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