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 10 of 14

Thread: MSAA with maginification's simple question

Threaded View

  1. #1
    Intern Contributor
    Join Date
    Dec 2012
    Posts
    74

    MSAA with maginification's simple question

    This program is only a version of the fbo code example of the the book OpenGL Programming Guide(the red book) fourth edition with a slight modification of multisampling and magnification instead of a copy-and-paste one. Since some fault within it, it runs on neither ATI nor NVIDIA graphics card which turns multisampling on.

    Code cpp:
    //fbo.c
    #include "stdio.h"
    #include "stdlib.h"
    #include "string.h"
    #include <windows.h>
    #include "gl\glew.h"
     
    #define GLUT_DISABLE_ATEXIT_HACK
     
    #include "glut.h"
     
    enum {Color, Depth, NumRenderbuffers};
     
    GLuint framebuffer, renderbuffer[NumRenderbuffers];
     
    void drawTiangle()
    {
        glColor3f(0.0f,1.0f,0.0f);
        glBegin(GL_TRIANGLES);
            glVertex3f(-1.0f,1.0f,0.0f);
            glVertex3f(1.0f,0.0f,0.0f);
            glVertex3f(-1.0f,-1.0f,0.0f);
        glEnd();
    }
     
    void init()
    {
        GLenum status;
        GLint samples;
        GLint bufs;
        GLenum err;
        char ErrorMessage[1024];
        int value;
        glEnable(GL_MULTISAMPLE_EXT);
        //glHint(GL_MULTISAMPLE_FILTER_HINT_NV, GL_NICEST); 
        glGetIntegerv (GL_SAMPLE_BUFFERS, &bufs);
        glGetIntegerv(GL_MAX_SAMPLES_EXT, &samples);
        printf("MSAA: buffers = %d samples = %d\n", bufs, samples);
        glGenFramebuffersEXT(NumRenderbuffers,renderbuffer);
        glBindRenderbufferEXT(GL_RENDERBUFFER_EXT,renderbuffer[Color]);
        //glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,GL_RGBA8, 256,256);
        glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT,4,GL_RGBA8, 256,256);
        glBindRenderbufferEXT(GL_RENDERBUFFER_EXT,renderbuffer[Depth]);
        //glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,GL_DEPTH_COMPONENT, 256,256);
        glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT,4,GL_DEPTH_COMPONENT24, 256,256);
        glGenFramebuffersEXT(1, & framebuffer);
        glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT,framebuffer);
        glFramebufferRenderbufferEXT(GL_DRAW_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT,GL_RENDERBUFFER_EXT,renderbuffer[Color]);
        glFramebufferRenderbufferEXT(GL_DRAW_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT,renderbuffer[Depth]);
        status=glCheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT);
        glEnable(GL_DEPTH_TEST);
    }
     
     
    void display()
    {
        GLenum status;
        glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT,framebuffer);
        status=glCheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT);
        glViewport(0,0,256,256);
        //red
        glClearColor(1.0,0.0,0.0,1.0);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glClearDepth(0.0f);
        drawTiangle();
        glViewport(0,0,512,512);
        glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT,framebuffer);
        glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT,0);
        status=glCheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT);
     
        //blue
        //glClearColor(0.0,0.0,1.0,1.0);
        //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        //glReadBuffer(GL_COLOR_ATTACHMENT0);
        glBlitFramebufferEXT(0,0,255,255,0,0,511,511,GL_COLOR_BUFFER_BIT,GL_NEAREST);
        status=glCheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT);
        glutSwapBuffers();
    }
     
    int main(int argc, char** argv)
    {
       glutInit(&argc, argv);
       glutInitDisplayMode(GLUT_DOUBLE| GLUT_RGBA | GLUT_DEPTH | GLUT_MULTISAMPLE);
       glutInitWindowSize(512, 512);
       glutInitWindowPosition(100, 100);
       glutCreateWindow("Frame buffer object");
     
       //Initialize the glew library.
       glewInit();
     
       init();
       glutDisplayFunc(display);
       glutMainLoop();
       return 0;
    }
    Last edited by Dark Photon; 12-03-2012 at 06:53 AM.

Posting Permissions

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