多采样opengl?

发布于 2024-09-13 10:49:47 字数 2312 浏览 6 评论 0原文

我运行多重采样的样本,但它工作不正确,似乎多重采样不适用 由于样本缓冲区和样本数为0。 我应该怎么做才能使其正确?

谢谢。

这是我的代码:

#include <stdio.h>
#include <stdlib.h>
#include <glew.h>
#include <GL/glut.h>

static int bgtoggle = 1;
void init(void)
{
GLint buf, sbuf;
int i, j;
glClearColor(0.0, 0.0, 0.0, 0.0);
glGetIntegerv(GL_SAMPLE_BUFFERS, &buf);
printf("number of sample buffers is %d\n", buf);
glGetIntegerv(GL_SAMPLES, &sbuf);
printf("number of samples is %d\n", sbuf);
glNewList(1, GL_COMPILE);
for (i = 0; i < 19; i++) {
    glPushMatrix();
    glRotatef(360.0*(float)i/19.0, 0.0, 0.0, 1.0);
    glColor3f (1.0, 1.0, 1.0);
    glLineWidth((i%3)+1.0);
    glBegin(GL_LINES);
    glVertex2f(0.25, 0.05);
    glVertex2f(0.9, 0.2);
    glEnd();
    glColor3f(0.0, 1.0, 1.0);
    glBegin(GL_TRIANGLES);
    glVertex2f(0.25, 0.0);
    glVertex2f(0.9, 0.0);
    glVertex2f(0.875, 0.10);
    glEnd();
    glPopMatrix();
}
glEndList();
glNewList(2, GL_COMPILE);
glColor3f(1.0, 0.5, 0.0);
glBegin(GL_QUADS);
for (i = 0; i < 16; i++) {
    for (j = 0; j < 16; j++) {
        if (((i + j) % 2) == 0) {
            glVertex2f(-2.0 + (i * 0.25), -2.0 + (j * 0.25));
            glVertex2f(-2.0 + (i * 0.25), -1.75 + (j * 0.25));
            glVertex2f(-1.75 + (i * 0.25), -1.75 + (j * 0.25));
            glVertex2f(-1.75 + (i * 0.25), -2.0 + (j * 0.25));
            }
        }
    }
glEnd();
glEndList();
  }
  void display(void)
  {
glClear(GL_COLOR_BUFFER_BIT);
glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
if (bgtoggle)
    glCallList(2);
glEnable(GL_MULTISAMPLE);
glPushMatrix();
glTranslatef(-1.0, 0.0, 0.0);
glCallList(1);
glPopMatrix();
glDisable(GL_MULTISAMPLE);
glPushMatrix();
glTranslatef(1.0, 0.0, 0.0);
glCallList(1);
glPopMatrix();
glutSwapBuffers();
   }
   void keyboard(unsigned char key, int x, int y)
   {
switch (key) {
case 'b':
case 'B':
    bgtoggle = !bgtoggle;
    glutPostRedisplay();
break;
case 27: /* Escape Key */   
exit(0);
break;
default:
break;
}
}
int main(int argc,char** argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_MULTISAMPLE|GLUT_DOUBLE|GLUT_DEPTH);
glutInitWindowPosition(100,100);
glutInitWindowSize(800,600);
glutCreateWindow("MultiSample");
init();
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
 }

I run sample of multi sampling but it work incorrect it seems that multi sampling don't applied
because of sample buffers & samples is 0.
what should i do to make it correct?

thanks.

this is my code:

#include <stdio.h>
#include <stdlib.h>
#include <glew.h>
#include <GL/glut.h>

static int bgtoggle = 1;
void init(void)
{
GLint buf, sbuf;
int i, j;
glClearColor(0.0, 0.0, 0.0, 0.0);
glGetIntegerv(GL_SAMPLE_BUFFERS, &buf);
printf("number of sample buffers is %d\n", buf);
glGetIntegerv(GL_SAMPLES, &sbuf);
printf("number of samples is %d\n", sbuf);
glNewList(1, GL_COMPILE);
for (i = 0; i < 19; i++) {
    glPushMatrix();
    glRotatef(360.0*(float)i/19.0, 0.0, 0.0, 1.0);
    glColor3f (1.0, 1.0, 1.0);
    glLineWidth((i%3)+1.0);
    glBegin(GL_LINES);
    glVertex2f(0.25, 0.05);
    glVertex2f(0.9, 0.2);
    glEnd();
    glColor3f(0.0, 1.0, 1.0);
    glBegin(GL_TRIANGLES);
    glVertex2f(0.25, 0.0);
    glVertex2f(0.9, 0.0);
    glVertex2f(0.875, 0.10);
    glEnd();
    glPopMatrix();
}
glEndList();
glNewList(2, GL_COMPILE);
glColor3f(1.0, 0.5, 0.0);
glBegin(GL_QUADS);
for (i = 0; i < 16; i++) {
    for (j = 0; j < 16; j++) {
        if (((i + j) % 2) == 0) {
            glVertex2f(-2.0 + (i * 0.25), -2.0 + (j * 0.25));
            glVertex2f(-2.0 + (i * 0.25), -1.75 + (j * 0.25));
            glVertex2f(-1.75 + (i * 0.25), -1.75 + (j * 0.25));
            glVertex2f(-1.75 + (i * 0.25), -2.0 + (j * 0.25));
            }
        }
    }
glEnd();
glEndList();
  }
  void display(void)
  {
glClear(GL_COLOR_BUFFER_BIT);
glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
if (bgtoggle)
    glCallList(2);
glEnable(GL_MULTISAMPLE);
glPushMatrix();
glTranslatef(-1.0, 0.0, 0.0);
glCallList(1);
glPopMatrix();
glDisable(GL_MULTISAMPLE);
glPushMatrix();
glTranslatef(1.0, 0.0, 0.0);
glCallList(1);
glPopMatrix();
glutSwapBuffers();
   }
   void keyboard(unsigned char key, int x, int y)
   {
switch (key) {
case 'b':
case 'B':
    bgtoggle = !bgtoggle;
    glutPostRedisplay();
break;
case 27: /* Escape Key */   
exit(0);
break;
default:
break;
}
}
int main(int argc,char** argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_MULTISAMPLE|GLUT_DOUBLE|GLUT_DEPTH);
glutInitWindowPosition(100,100);
glutInitWindowSize(800,600);
glutCreateWindow("MultiSample");
init();
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
 }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

删除会话 2024-09-20 10:49:47

创建 GLContext 时设置适当的 GLCapability。在绘制代码之前,请确保有 glEnable(GL_LINE_SMOOTH);glEnable(GL_MULTISAMPLE);

您尝试过这个吗:

glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA | GLUT_MULTISAMPLE );
glEnable(GL_MULTISAMPLE);

也尝试使用 glEnable(GLUT_MULTISAMPLE_ARB) 代替。

Set appropriate GLCapabilities while creating GLContext. Make sure there are glEnable(GL_LINE_SMOOTH); and glEnable(GL_MULTISAMPLE); before drawing code.

Have You tried this one:

glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA | GLUT_MULTISAMPLE );
glEnable(GL_MULTISAMPLE);

Try also to use glEnable(GLUT_MULTISAMPLE_ARB) instead.

吾家有女初长成 2024-09-20 10:49:47

是不是那么简单,除了启用多重采样之外,您还需要创建一个 OpenGL 上下文,其中示例 > 0,这取决于窗口系统,并且取决于API。如果您提供用于创建 OpenGL 上下文/窗口的 API,我们将能够准确地告诉您它是如何完成的。

Is not that simple, beside enabling multisampling, you need to create a OpenGL context with samples > 0, and that is window-system dependant, and API dependant. If you provide what API are you using to create the OpenGL context/window, and we'll be able to tell you exactly how it is done.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文