简体   繁体   中英

JOGL Smoothness

I'm using JOGL - OpenGL. I have ribbons with colored edges that I create using triangle primitives as shown in the wire frame image. The edges are made up of triangles themselves. How do I get smooth edges? I looked up anti-aliasing, and I'm not sure if that`s the approach I need to take.

I`m open to making design changes, I need the border lines and the overlapping pattern format. I have tried the tried the below and blending, The issue is the triangles are too close to make any difference.

 gl.glDisable(GL2.GL_LINE_SMOOTH);
 gl.glDisable(GL2.GL_POLYGON_SMOOTH);
 gl.glEnable(GL2.GL_MULTISAMPLE);

在此处输入图片说明

没有多重采样

多重采样

Can someone point me in the right direction. Here is the code.

@Override
public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();

    int ind = 0;
    int nind = 0; // normal index

    gl.glColorMaterial(GL2.GL_FRONT, GL2.GL_DIFFUSE);
    gl.glEnable(GL2.GL_COLOR_MATERIAL);
    gl.glRotatef(0, 0, 1, 0);
    gl.glTranslatef(-tr_x, -tr_y, -tr_z);

    while (ind < fvert.size()) {
        gl.glPushMatrix();
            gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
        gl.glBegin(GL2.GL_TRIANGLES);
        gl.glColor4f(.9f, .0f, 0.0f, 0.5f); // upper border
        gl.glNormal3f(fnorm.get(nind + 4).x, fnorm.get(nind + 4).y, fnorm.get(nind + 4).z);
        gl.glVertex3f(fvert.get(ind + 8).x, fvert.get(ind + 8).y, fvert.get(ind + 8).z);
        gl.glVertex3f(fvert.get(ind + 9).x, fvert.get(ind + 9).y, fvert.get(ind + 9).z);
        gl.glVertex3f(fvert.get(ind + 10).x, fvert.get(ind + 10).y, fvert.get(ind + 10).z);

        gl.glNormal3f(fnorm.get(nind + 5).x, fnorm.get(nind + 5).y, fnorm.get(nind + 5).z);
        gl.glVertex3f(fvert.get(ind + 10).x, fvert.get(ind + 10).y, fvert.get(ind + 10).z);
        gl.glVertex3f(fvert.get(ind + 11).x, fvert.get(ind + 11).y, fvert.get(ind + 11).z);
        gl.glVertex3f(fvert.get(ind + 8).x, fvert.get(ind + 8).y, fvert.get(ind + 8).z);

        gl.glColor4f(.9f, .9f, 0.2f, 0.5f);// Triangle pair upper
        gl.glNormal3f(fnorm.get(nind).x, fnorm.get(nind).y, fnorm.get(nind).z);
        gl.glVertex3f(fvert.get(ind + 2).x, fvert.get(ind + 2).y, fvert.get(ind + 2).z);
        gl.glVertex3f(fvert.get(ind).x, fvert.get(ind).y, fvert.get(ind).z);
        gl.glVertex3f(fvert.get(ind + 1).x, fvert.get(ind + 1).y, fvert.get(ind + 1).z);

        gl.glNormal3f(fnorm.get(nind + 1).x, fnorm.get(nind + 1).y, fnorm.get(nind + 1).z);
        gl.glVertex3f(fvert.get(ind + 3).x, fvert.get(ind + 3).y, fvert.get(ind + 3).z);
        gl.glVertex3f(fvert.get(ind).x, fvert.get(ind).y, fvert.get(ind).z);
        gl.glVertex3f(fvert.get(ind + 2).x, fvert.get(ind + 2).y, fvert.get(ind + 2).z);

        gl.glColor4f(.9f, .0f, 0.0f, 0.5f); // lower border
        gl.glNormal3f(fnorm.get(nind + 6).x, fnorm.get(nind + 6).y, fnorm.get(nind + 6).z);
        gl.glVertex3f(fvert.get(ind + 14).x, fvert.get(ind + 14).y, fvert.get(ind + 14).z);
        gl.glVertex3f(fvert.get(ind + 12).x, fvert.get(ind + 12).y, fvert.get(ind + 12).z);
        gl.glVertex3f(fvert.get(ind + 13).x, fvert.get(ind + 13).y, fvert.get(ind + 13).z);

        gl.glNormal3f(fnorm.get(nind + 7).x, fnorm.get(nind + 7).y, fnorm.get(nind + 7).z);
        gl.glVertex3f(fvert.get(ind + 15).x, fvert.get(ind + 15).y, fvert.get(ind + 15).z);
        gl.glVertex3f(fvert.get(ind + 12).x, fvert.get(ind + 12).y, fvert.get(ind + 12).z);
        gl.glVertex3f(fvert.get(ind + 14).x, fvert.get(ind + 14).y, fvert.get(ind + 14).z);

        gl.glColor4f(.9f, .9f, 0.2f, 0.5f);// triangle pair lower
        gl.glNormal3f(fnorm.get(nind + 2).x, fnorm.get(nind + 2).y, fnorm.get(nind + 2).z);
        gl.glVertex3f(fvert.get(ind + 6).x, fvert.get(ind + 6).y, fvert.get(ind + 6).z);
        gl.glVertex3f(fvert.get(ind + 4).x, fvert.get(ind + 4).y, fvert.get(ind + 4).z);
        gl.glVertex3f(fvert.get(ind + 5).x, fvert.get(ind + 5).y, fvert.get(ind + 5).z);

        gl.glNormal3f(fnorm.get(nind + 3).x, fnorm.get(nind + 3).y, fnorm.get(nind + 3).z);
        gl.glVertex3f(fvert.get(ind + 7).x, fvert.get(ind + 7).y, fvert.get(ind + 7).z);
        gl.glVertex3f(fvert.get(ind + 4).x, fvert.get(ind + 4).y, fvert.get(ind + 4).z);
        gl.glVertex3f(fvert.get(ind + 6).x, fvert.get(ind + 6).y, fvert.get(ind + 6).z);

        gl.glEnd();
        gl.glPopMatrix();

        ind = ind + 16;
        nind = nind + 8;
    }

    gl.glFlush();
}

@Override
public void init(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    gl.glClearColor(.0f, .0f, .0f, 0.0f);

    gl.glEnable(GL2.GL_DEPTH_TEST);
    gl.glDepthFunc(GL2.GL_LESS);
    gl.glEnable(GL2.GL_TEXTURE_GEN_S);
    gl.glEnable(GL2.GL_TEXTURE_1D);
    gl.glEnable(GL2.GL_CULL_FACE);
    gl.glEnable(GL2.GL_LIGHTING);
    gl.glEnable(GL2.GL_LIGHT0);
    gl.glEnable(GL2.GL_AUTO_NORMAL);
    gl.glEnable(GL2.GL_NORMALIZE);
    gl.glFrontFace(GL2.GL_CCW);
    gl.glCullFace(GL2.GL_BACK);

    gl.glPolygonMode( GL2.GL_FRONT_AND_BACK,GL2.GL_LINE );

}

Maybe you should enable multisampling in your GLCapabilities Example :

GLCapabilities STANDARD_CAPS;
STANDARD_CAPS = new GLCapabilities(GLProfile.get(GLProfile.GL2)); //I assume taht you are using GL2
STANDARD_CAPS.setBackgroundOpaque(true); //opaque background
STANDARD_CAPS.setHardwareAccelerated(true); //hardware acceleration
STANDARD_CAPS.setSampleBuffers(true); //Enable sampling
STANDARD_CAPS.setNumSamples(8); //8 Samples

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM