OpenGL多视口

#include <gl/glew.h>
#include <gl/freeglut.h>
#include <iostream>

int window_width = 1024;
int window_height = 800;
float rtri = 0.0;
float rquad = 0.0;
void init();
void display();
void resize(int w, int h);
int main(int argc, char ** argv)
{
   glutInit(&argc, argv);
   glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
   glutInitWindowSize(1024, 800);
   glutCreateWindow("OpenGL");
   GLenum res = glewInit();
   if (res != GLEW_OK) 
   {
       std::cout << glewGetErrorString(res) << std::endl;
   }

   init();
   glutDisplayFunc(display);
   glutReshapeFunc(resize);
   glutMainLoop();
   return EXIT_SUCCESS;
}

void init()
{
    glClearColor(0.0, 0.0, 0.0, 1.0);
}

void display()
{  
    glClear(GL_COLOR_BUFFER_BIT);
    glLoadIdentity();
    for (int loop = 0; loop < 4; ++loop)
    {
        if (0 == loop)
        {
           glViewport(0, 0, window_width/2, window_height/2);
           glMatrixMode(GL_PROJECTION);
           glLoadIdentity();
           gluOrtho2D(-20, 20, -20, 20);
        }
        if (1 == loop)
        {
            glViewport(window_width/2, 0, window_width, window_height/2);
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            gluOrtho2D(-20, 20, -20, 20);
        }
        if (2 == loop)
        {
            glViewport(0, window_height/2, window_width/2, window_height);
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            gluOrtho2D(-20, 20, -20, 20);
        }
        if (3 == loop)
        {
           glViewport(window_width/2, window_height/2, window_width, window_height) ;
           glMatrixMode(GL_PROJECTION);
           glLoadIdentity();
           gluOrtho2D(-20, 20, -20, 20);
        }
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glClear(GL_DEPTH_BUFFER_BIT);
        if (0 == loop)
        {
            glBegin(GL_QUADS);
                glVertex2f(-10, -10);
                glVertex2f(10, -10);
                glVertex2f(10, 10);
                glVertex2f(-10, 10);
            glEnd();
        }
        if (1 == loop)
        {
            glBegin(GL_QUADS);
                glVertex2f(-10, -10);
                glVertex2f(10, -10);
                glVertex2f(10, 10);
                glVertex2f(-10, 10);
            glEnd();
        }
        if (2 == loop)
        {
            glBegin(GL_QUADS);
                glVertex2f(-10, -10);
                glVertex2f(10, -10);
                glVertex2f(10, 10);
                glVertex2f(-10, 10);
            glEnd();
        }
        if (3 == loop)
        {
            glBegin(GL_QUADS);
                glVertex2f(-10, -10);
                glVertex2f(10, -10);
                glVertex2f(10, 10);
                glVertex2f(-10, 10);
            glEnd();
        }
    }
    glutSwapBuffers();
}

void resize(int w, int h)
{
     window_height = h; 
     window_width = w;
}

转载于:https://www.cnblogs.com/nmgxbc/p/3505744.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值