0

我正在尝试通过使用 alpha 使矩形变为 50% 的透明度。但它不起作用,我的形状不再出现。

有什么解决方案可以解决这个问题吗?

(在对象类中绘制矩形函数)

void Object::drawRect(GLint x1, GLint y1,
              GLint x2, GLint y2,
              GLint x3, GLint y3,
              GLint x4, GLint y4){
    glPushMatrix();
    glBegin(GL_QUADS);
        glVertex2i(x1, y1);
        glVertex2i(x2, y2);
        glVertex2i(x3, y3);
        glVertex2i(x4, y4); 
    glEnd();
    glPopMatrix();
}

(渲染场景部分)

void renderScene(void){ // Render function definition
    glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // RGBA
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0, 1000, 0, 600); // Set canvas to 800x600 pixels.

    Object o = Object();

    glColor4ub(50,50,50,0.5);
    o.drawRect(150,30,60,30,60,40,150,40);

    glFlush(); // Clear all GL executions.
    glFinish(); // Block until all GL executions are completed.
    glDisable(GL_BLEND);
    glutSwapBuffers(); // Swap foreground with back buffer.
    glutPostRedisplay(); // Update the frame.
}

(主要部分)

int main(){
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    glutInitWindowSize(1000, 600); // OpenGL window size.
    glutInitWindowPosition(150, 150); // Window position on the screen.
    glEnable( GL_DEPTH_TEST );
    glEnable (GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 

    glutCreateWindow("Bossi"); // OpenGL window title.
    //glutFullScreen(); 
    glutDisplayFunc(renderScene); // Load render function.
    glutMouseFunc(mouseControl); // Enable mouse button function.   
    glutKeyboardFunc(keyboardControl1); // Enable ASCII keyboard control.
    glutSpecialFunc(keyboardControl2); // Enable special keys control.      
    glutMainLoop(); // Loop frame forever.

    system("PAUSE"); // Stop the frame.
    return 0; // Close program.
}
4

0 回答 0