#include #include #include GLuint framebuffer, renderbuffer; #define WIDTH 300 #define HEIGHT 350 int numSamples; void init() { glGetIntegerv(GL_MAX_SAMPLES_EXT, &numSamples); glGenFramebuffersEXT(1, &framebuffer); glGenRenderbuffersEXT(1, &renderbuffer); glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer); glBindRenderbufferEXT(GL_RENDERBUFFER, renderbuffer); glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, numSamples, GL_RGBA, WIDTH, HEIGHT); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer); glEnable (GL_MULTISAMPLE); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, WIDTH, 0.0, HEIGHT, -1.0, 1.0); } void display() { glBindFramebufferEXT(GL_FRAMEBUFFER,framebuffer); glClearColor(0.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); glEnable(GL_BLEND); GLenum src_factor, dst_factor; src_factor = GL_SRC_ALPHA; dst_factor = GL_ONE_MINUS_SRC_ALPHA; glBlendFunc (src_factor, dst_factor); glColor4f (0.0, 1.0, 0.0, 0.7); glMatrixMode(GL_MODELVIEW); glBegin(GL_POLYGON); glVertex3f (140, 55, 0.0); glVertex3f (220, 55, 0.0); glVertex3f (220, 165, 0.0); glVertex3f (140, 165, 0.0); glEnd(); glBindFramebufferEXT(GL_READ_FRAMEBUFFER, framebuffer); glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, 0); glBlitFramebuffer(0, 0, WIDTH, HEIGHT, 0, 0, WIDTH, HEIGHT, GL_COLOR_BUFFER_BIT, GL_NEAREST); glBindFramebuffer(GL_FRAMEBUFFER, 0); glutSwapBuffers(); } void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: /* Escape Key */ exit(0); break; default: break; } } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE| GLUT_RGBA | GLUT_ALPHA); glutInitWindowSize(WIDTH, HEIGHT); glutInitWindowPosition(100, 100); glutCreateWindow("msaa"); init(); glutDisplayFunc(display); glutKeyboardFunc (keyboard); glutMainLoop(); return 0; }