Using OpenGL with SWT

atie의 이미지

eclipse.org에 올라온 SWT에서 OpenGL을 쓰는 것에 대한 소개 글.
http://www.eclipse.org/articles/Article-SWT-OpenGL/opengl.html

swt.opengl/gtk 소스를 보려면.
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.opengl/gtk/

Quote:
A scene may be drawn by making a series of calls to methods defined in the GL and GLU classes once the context is made current. The GL class exposes over 330 commands. There are essentially one-to-one mappings between methods defined in the GL and GLU classes and their native counterparts. Figure 3 provides sample code that draws a triangle. For every gl* function in C, there is a corresponding GL.gl* Java method, and for every enumerated value GL_* in C, there is an equivalent GL.GL_* Java constant. Adopting the same APIs in the SWT OpenGL plug-in makes it easy for those familiar with the C language APIs to code in Java.

(a) C Code

void drawScene() {
    glClear(GL_COLOR_BUFFER_BIT
        | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glTranslatef(0.0f, 0.0f, -5.0f);

    glBegin(GL_TRIANGLES);
        glVertex3f(-1.0f, -1.0f, 0.0f);
        glVertex3f(1.0f, -1.0f, 0.0f);
        glVertex3f(0.0f, 1.0f, 0.0f);
    glEnd();

    glutSwapBuffers();
}

	
(b) Java Code

public void drawScene() {
    GL.glClear(GL.GL_COLOR_BUFFER_BIT
        | GL.GL_DEPTH_BUFFER_BIT);
    GL.glLoadIdentity();
    GL.glTranslatef(0.0f, 0.0f, -5.0f);

    GL.glBegin(GL.GL_TRIANGLES);
        GL.glVertex3f(-1.0f, -1.0f, 0.0f);
        GL.glVertex3f(1.0f, -1.0f, 0.0f);
        GL.glVertex3f(0.0f, 1.0f, 0.0f);
    GL.glEnd();

    glContext.swapBuffers();
}

어디까지 진행이 되었나 요약을 하자면,

Quote:
Until recently, in order to exploit advanced 2D graphics, one had to depend on off-screen drawing. By relying on a BufferedImage one could use Java2D APIs to draw in memory, transfer the image to an SWT image, and then render it on any SWT component (see [2] for details). However, the drawback of this technique was added storage and processing time requirements. These limitations were overcome in milestone 5 of the 3.1 release through a new SWT API that utilizes native Cairo or GDI+ graphics libraries. Developers now can use transparency, rotation, shearing, brushes, pens and many more techniques for enhancing graphical output, directly in SWT. Unfortunately, even with these additions, the realm of high-performance 3D graphics is still out of reach.
다크슈테펜의 이미지

이게 애플에서 스윙에 쿼츠 가속을 해주는 것과 비슷한 효과인가요...?

인생이란게 다 그런게 아니겠어요....? 뭘(?)
http://schutepen.egloos.com

atie의 이미지

darkschutepen wrote:
이게 애플에서 스윙에 쿼츠 가속을 해주는 것과 비슷한 효과인가요...?

아닙니다. SWT에서 2D 그리고 3D 그래픽을 OpenGL을 써서 할 수 있게 라이브러리를 plugin으로 만든 것입니다.

----
I paint objects as I think them, not as I see them.
atie's minipage