ppp.cpp

来自「apple.rar」· C++ 代码 · 共 55 行

CPP
55
字号
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glaux.h>

void myinit(void);
void CALLBACK myReshape(GLsizei w, GLsizei h);
void CALLBACK display(void);

  /* 初始化 alpha 融合的参数 */
void myinit(void)
  {
    glEnable (GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glShadeModel (GL_FLAT);
    glClearColor (0.0, 0.0, 0.0, 0.0);
  }

void CALLBACK display(void)
  {
    glClear(GL_COLOR_BUFFER_BIT);

    glColor4f (1.0, 0.0, 0.0, 0.7);
    glRectf (0.25, 0.4, 0.75, 0.9);

    glColor4f (0.0, 1.0, 0.0, 0.5);
    glRectf (0.1, 0.1, 0.6, 0.6);
    
    glColor4f (0.0, 0.0, 1.0, 0.3);
    glRectf (0.4, 0.1, 0.9, 0.6);
    
    glFlush();
  }

void CALLBACK myReshape(GLsizei w, GLsizei h)
  {
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    if (w <= h)
      gluOrtho2D (0.0, 1.0, 0.0, 1.0*(GLfloat)h/(GLfloat)w);
    else
      gluOrtho2D (0.0, 1.0*(GLfloat)w/(GLfloat)h, 0.0, 1.0);
    glMatrixMode(GL_MODELVIEW);
  }

void main(void)
  {
    auxInitDisplayMode (AUX_SINGLE | AUX_RGBA);
    auxInitPosition (0, 0, 500, 500);
    auxInitWindow ("Alpha 2D Blending");
    myinit();
    auxReshapeFunc (myReshape);
    auxMainLoop(display);
  }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?