2 * PROJECT: NyARToolkit JOGL utilities.
\r
3 * --------------------------------------------------------------------------------
\r
4 * This work is based on the original ARToolKit developed by
\r
7 * HITLab, University of Washington, Seattle
\r
8 * http://www.hitl.washington.edu/artoolkit/
\r
10 * The NyARToolkit is Java version ARToolkit class library.
\r
11 * Copyright (C)2008 R.Iizuka
\r
13 * This program is free software; you can redistribute it and/or
\r
14 * modify it under the terms of the GNU General Public License
\r
15 * as published by the Free Software Foundation; either version 2
\r
16 * of the License, or (at your option) any later version.
\r
18 * This program is distributed in the hope that it will be useful,
\r
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
21 * GNU General Public License for more details.
\r
23 * You should have received a copy of the GNU General Public License
\r
24 * along with this framework; if not, write to the Free Software
\r
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
27 * For further information please contact.
\r
28 * http://nyatla.jp/nyatoolkit/
\r
29 * <airmail(at)ebony.plala.or.jp>
\r
32 package jp.nyatla.nyartoolkit.jogl.utils;
\r
34 import java.nio.ByteBuffer;
\r
35 import java.nio.IntBuffer;
\r
37 import javax.media.opengl.GL;
\r
38 import javax.media.opengl.glu.GLU;
\r
40 import jp.nyatla.nyartoolkit.core.types.*;
\r
42 * NyARToolkit用のJOGL支援関数群
\r
44 public class NyARGLUtil
\r
46 private javax.media.opengl.GL _gl;
\r
48 private javax.media.opengl.glu.GLU _glu;
\r
50 public NyARGLUtil(javax.media.opengl.GL i_gl)
\r
53 this._glu = new GLU();
\r
57 * GLNyARRaster_RGBをバックグラウンドに書き出す。
\r
61 public void drawBackGround(GLNyARRaster_RGB i_raster, double i_zoom)
\r
63 IntBuffer texEnvModeSave = IntBuffer.allocate(1);
\r
64 boolean lightingSave;
\r
65 boolean depthTestSave;
\r
66 javax.media.opengl.GL gl = this._gl;
\r
67 final NyARIntSize rsize=i_raster.getSize();
\r
69 // Prepare an orthographic projection, set camera position for 2D drawing, and save GL state.
\r
70 gl.glGetTexEnviv(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, texEnvModeSave); // Save GL texture environment mode.
\r
71 if (texEnvModeSave.array()[0] != GL.GL_REPLACE) {
\r
72 gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);
\r
74 lightingSave = gl.glIsEnabled(GL.GL_LIGHTING); // Save enabled state of lighting.
\r
75 if (lightingSave == true) {
\r
76 gl.glDisable(GL.GL_LIGHTING);
\r
78 depthTestSave = gl.glIsEnabled(GL.GL_DEPTH_TEST); // Save enabled state of depth test.
\r
79 if (depthTestSave == true) {
\r
80 gl.glDisable(GL.GL_DEPTH_TEST);
\r
82 gl.glMatrixMode(GL.GL_PROJECTION);
\r
84 gl.glLoadIdentity();
\r
85 _glu.gluOrtho2D(0.0,rsize.w, 0.0,rsize.h);
\r
86 gl.glMatrixMode(GL.GL_MODELVIEW);
\r
88 gl.glLoadIdentity();
\r
89 arglDispImageStateful(i_raster, i_zoom);
\r
91 // Restore previous projection, camera position, and GL state.
\r
92 gl.glMatrixMode(GL.GL_PROJECTION);
\r
94 gl.glMatrixMode(GL.GL_MODELVIEW);
\r
96 if (depthTestSave) {
\r
97 gl.glEnable(GL.GL_DEPTH_TEST); // Restore enabled state of depth test.
\r
100 gl.glEnable(GL.GL_LIGHTING); // Restore enabled state of lighting.
\r
102 if (texEnvModeSave.get(0) != GL.GL_REPLACE) {
\r
103 gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, texEnvModeSave.get(0)); // Restore GL texture environment mode.
\r
109 * arglDispImageStateful関数モドキ
\r
113 private void arglDispImageStateful(GLNyARRaster_RGB i_raster, double zoom)
\r
115 javax.media.opengl.GL gl_ = this._gl;
\r
116 final NyARIntSize rsize = i_raster.getSize();
\r
118 IntBuffer params = IntBuffer.allocate(4);
\r
119 zoomf = (float) zoom;
\r
120 gl_.glDisable(GL.GL_TEXTURE_2D);
\r
121 gl_.glGetIntegerv(GL.GL_VIEWPORT, params);
\r
122 gl_.glPixelZoom(zoomf * ((float) (params.get(2)) / (float) rsize.w), -zoomf * ((float) (params.get(3)) / (float) rsize.h));
\r
123 gl_.glWindowPos2f(0.0f, (float) rsize.h);
\r
124 gl_.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
\r
125 ByteBuffer buf = ByteBuffer.wrap(i_raster.getGLRgbArray());
\r
126 gl_.glDrawPixels(rsize.w,rsize.h, i_raster.getGLPixelFlag(), GL.GL_UNSIGNED_BYTE, buf);
\r