Thursday, June 2, 2011

gluBuild2DMipmaps example c c++ java objc

Name
gluBuild2DMipmaps — builds a two-dimensional mipmap

C Specification

GLint gluBuild2DMipmaps(GLenum  target,
GLint  internalFormat,
GLsizei  width,
GLsizei  height,
GLenum  format,
GLenum  type,
const void *  data);

Parameters

target
Specifies the target texture. Must be GLU_TEXTURE_2D.
internalFormat
Requests the internal storage format of the texture image. The most current version of the SGI implementation of GLU does not check this value for validity before passing it on to the underlying OpenGL implementation. A value that is not accepted by the OpenGL implementation will lead to an OpenGL error. The benefit of not checking this value at the GLU level is that OpenGL extensions can add new internal texture formats without requiring a revision of the GLU implementation. Older implementations of GLU check this value and raise a GLU error if it is not 1, 2, 3, or 4 or one of the following symbolic constants: GLU_ALPHA, GLU_ALPHA4, GLU_ALPHA8, GLU_ALPHA12, GLU_ALPHA16, GLU_LUMINANCE, GLU_LUMINANCE4, GLU_LUMINANCE8, GLU_LUMINANCE12, GLU_LUMINANCE16,GLU_LUMINANCE_ALPHA, GLU_LUMINANCE4_ALPHA4, GLU_LUMINANCE6_ALPHA2, GLU_LUMINANCE8_ALPHA8, GLU_LUMINANCE12_ALPHA4, GLU_LUMINANCE12_ALPHA12, GLU_LUMINANCE16_ALPHA16, GLU_INTENSITY, GLU_INTENSITY4, GLU_INTENSITY8, GLU_INTENSITY12, GLU_INTENSITY16, GLU_RGB, GLU_R3_G3_B2,GLU_RGB4, GLU_RGB5, GLU_RGB8, GLU_RGB10, GLU_RGB12, GLU_RGB16, GLU_RGBA, GLU_RGBA2, GLU_RGBA4, GLU_RGB5_A1, GLU_RGBA8, GLU_RGB10_A2, GLU_RGBA12, or GLU_RGBA16.
width, height
Specifies in pixels the width and height, respectively, of the texture image.
format
Specifies the format of the pixel data. Must be one of GLU_COLOR_INDEX, GLU_DEPTH_COMPONENT, GLU_RED, GLU_GREEN, GLU_BLUE, GLU_ALPHA, GLU_RGB, GLU_RGBA, GLU_BGR, GLU_BGRA, GLU_LUMINANCE, or GLU_LUMINANCE_ALPHA.
type
Specifies the data type for data. Must be one of GLU_UNSIGNED_BYTE, GLU_BYTE, GLU_BITMAP, GLU_UNSIGNED_SHORT, GLU_SHORT, GLU_UNSIGNED_INT, GLU_INT, GLU_FLOAT, GLU_UNSIGNED_BYTE_3_3_2, GLU_UNSIGNED_BYTE_2_3_3_REV, GLU_UNSIGNED_SHORT_5_6_5, GLU_UNSIGNED_SHORT_5_6_5_REV,GLU_UNSIGNED_SHORT_4_4_4_4, GLU_UNSIGNED_SHORT_4_4_4_4_REV, GLU_UNSIGNED_SHORT_5_5_5_1, GLU_UNSIGNED_SHORT_1_5_5_5_REV, GLU_UNSIGNED_INT_8_8_8_8, GLU_UNSIGNED_INT_8_8_8_8_REV, GLU_UNSIGNED_INT_10_10_10_2, or GLU_UNSIGNED_INT_2_10_10_10_REV.
data
Specifies a pointer to the image data in memory.

Description

gluBuild2DMipmaps builds a series of prefiltered two-dimensional texture maps of decreasing resolutions called a mipmap. This is used for the antialiasing of texture-mapped primitives.
A return value of zero indicates success, otherwise a GLU error code is returned (see gluErrorString).
Initially, the width and height of data are checked to see if they are a power of 2. If not, a copy of data (not data), is scaled up or down to the nearest power of 2. This copy will be used for subsequent mipmapping operations described below. (If width or height is exactly between powers of 2, then the copy of data will scale upwards.) For example, if width is 57 and height is 23, then a copy of data will scale up to 64 in width and down to 16 in depth, before mipmapping takes place.
Then, proxy textures (see glTexImage2D) are used to determine if the implementation can fit the requested texture. If not, both dimensions are continually halved until it fits. (If the OpenGL version is \(<= 1.0, both maximum texture dimensions are clamped to the value returned by glGetIntegerv with the argument GLU_MAX_TEXTURE_SIZE.)
Next, a series of mipmap levels is built by decimating a copy of data in half along both dimensions until size 1 × 1 is reached. At each level, each texel in the halved mipmap level is an average of the corresponding four texels in the larger mipmap level. (In the case of rectangular images, the decimation will ultimately reach an N × 1 or 1 × N configuration. Here, two texels are averaged instead.)
glTexImage2D is called to load each of these mipmap levels. Level 0 is a copy of data. The highest level is log 2  max  width height . For example, if width is 64 and height is 16 and the implementation can store a texture of this size, the following mipmap levels are built: 64 × 16 , 32 × 8 , 16 × 4 , 8 × 2 , 4 × 1 , 2 × 1 , and 1 × 1 These correspond to levels 0 through 6, respectively.
See the glTexImage1D reference page for a description of the acceptable values for format parameter. See the glDrawPixels reference page for a description of the acceptable values for type parameter.

Notes

Note that there is no direct way of querying the maximum level. This can be derived indirectly via glGetTexLevelParameter. First, query for the width and height actually used at level 0. (The width and height may not be equal to width and height respectively since proxy textures might have scaled them to fit the implementation.) Then the maximum level can be derived from the formula log 2  max  width height .
Formats GLU_BGR, and GLU_BGRA, and types GLU_UNSIGNED_BYTE_3_3_2, GLU_UNSIGNED_BYTE_2_3_3_REV, GLU_UNSIGNED_SHORT_5_6_5, GLU_UNSIGNED_SHORT_5_6_5_REV, GLU_UNSIGNED_SHORT_4_4_4_4, GLU_UNSIGNED_SHORT_4_4_4_4_REV, GLU_UNSIGNED_SHORT_5_5_5_1, GLU_UNSIGNED_SHORT_1_5_5_5_REV,GLU_UNSIGNED_INT_8_8_8_8, GLU_UNSIGNED_INT_8_8_8_8_REV, GLU_UNSIGNED_INT_10_10_10_2, and GLU_UNSIGNED_INT_2_10_10_10_REV are only available if the GL version is 1.2 or greater and if the GLU version is 1.3 or greater.

Errors

GLU_INVALID_VALUE is returned if width or height is < 1.
GLU_INVALID_ENUM is returned if internalFormat, format, or type is not legal.
GLU_INVALID_OPERATION is returned if type is GLU_UNSIGNED_BYTE_3_3_2 or GLU_UNSIGNED_BYTE_2_3_3_REV and format is not GLU_RGB.
GLU_INVALID_OPERATION is returned if type is GLU_UNSIGNED_SHORT_5_6_5 or GLU_UNSIGNED_SHORT_5_6_5_REV and format is not GLU_RGB.
GLU_INVALID_OPERATION is returned if type is GLU_UNSIGNED_SHORT_4_4_4_4 or GLU_UNSIGNED_SHORT_4_4_4_4_REV and format is neither GLU_RGBA nor GLU_BGRA.
GLU_INVALID_OPERATION is returned if type is GLU_UNSIGNED_SHORT_5_5_5_1 or GLU_UNSIGNED_SHORT_1_5_5_5_REV and format is neither GLU_RGBA nor GLU_BGRA.
GLU_INVALID_OPERATION is returned if type is GLU_UNSIGNED_INT_8_8_8_8 or GLU_UNSIGNED_INT_8_8_8_8_REV and format is neither GLU_RGBA nor GLU_BGRA.
GLU_INVALID_OPERATION is returned if type is GLU_UNSIGNED_INT_10_10_10_2 or GLU_UNSIGNED_INT_2_10_10_10_REV and format is neither GLU_RGBA nor GLU_BGRA.

Copyright

Copyright © 1991-2006 Silicon Graphics, Inc. This document is licensed under the SGI Free Software B License. For details, see http://oss.sgi.com/projects/FreeB/.


Example 1.

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0 );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0 );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0 );
GLint ret = gluBuild2DMipmaps(GL_TEXTURE_2D, gl_InternalFormat(),
m_iWidth, m_iHeight, gl_RasterFormat(), gl_RasterType(),
&m_pSrcBitmap[0]);



------------------------------------------------------------------------------------------
Example 2


GLint ret = gluBuild2DMipmapLevels(GL_TEXTURE_2D,
gl_InternalFormat(),
m_iWidth, m_iHeight, gl_RasterFormat(), gl_RasterType(),
0, 0, 0,
&m_pSrcBitmap[0]);

gluBuild2DMipmapLevels example c c++ java objc

Name
gluBuild2DMipmapLevels — builds a subset of two-dimensional mipmap levels

C Specification

GLint gluBuild2DMipmapLevels(GLenum  target,
GLint  internalFormat,
GLsizei  width,
GLsizei  height,
GLenum  format,
GLenum  type,
GLint  level,
GLint  base,
GLint  max,
const void *  data);

Parameters

target
Specifies the target texture. Must be GLU_TEXTURE_2D.
internalFormat
Requests the internal storage format of the texture image. The most current version of the SGI implementation of GLU does not check this value for validity before passing it on to the underlying OpenGL implementation. A value that is not accepted by the OpenGL implementation will lead to an OpenGL error. The benefit of not checking this value at the GLU level is that OpenGL extensions can add new internal texture formats without requiring a revision of the GLU implementation. Older implementations of GLU check this value and raise a GLU error if it is not 1, 2, 3, or 4 or one of the following symbolic constants: GLU_ALPHA, GLU_ALPHA4, GLU_ALPHA8, GLU_ALPHA12, GLU_ALPHA16, GLU_LUMINANCE, GLU_LUMINANCE4, GLU_LUMINANCE8, GLU_LUMINANCE12, GLU_LUMINANCE16,GLU_LUMINANCE_ALPHA, GLU_LUMINANCE4_ALPHA4, GLU_LUMINANCE6_ALPHA2, GLU_LUMINANCE8_ALPHA8, GLU_LUMINANCE12_ALPHA4, GLU_LUMINANCE12_ALPHA12, GLU_LUMINANCE16_ALPHA16, GLU_INTENSITY, GLU_INTENSITY4, GLU_INTENSITY8, GLU_INTENSITY12, GLU_INTENSITY16, GLU_RGB, GLU_R3_G3_B2,GLU_RGB4, GLU_RGB5, GLU_RGB8, GLU_RGB10, GLU_RGB12, GLU_RGB16, GLU_RGBA, GLU_RGBA2, GLU_RGBA4, GLU_RGB5_A1, GLU_RGBA8, GLU_RGB10_A2, GLU_RGBA12, or GLU_RGBA16. (gluBuild2DMipmapLevels)
width, height
Specifies the width and height, respectively, in pixels of the texture image. These should be a power of 2.
format
Specifies the format of the pixel data. Must be one of GLU_COLOR_INDEX, GLU_DEPTH_COMPONENT, GLU_RED, GLU_GREEN, GLU_BLUE, GLU_ALPHA, GLU_RGB, GLU_RGBA, GLU_BGR, GLU_BGRA, GLU_LUMINANCE, or GLU_LUMINANCE_ALPHA.
type
Specifies the data type for data. Must be one of GLU_UNSIGNED_BYTE, GLU_BYTE, GLU_BITMAP, GLU_UNSIGNED_SHORT, GLU_SHORT, GLU_UNSIGNED_INT, GLU_INT, GLU_FLOAT, GLU_UNSIGNED_BYTE_3_3_2, GLU_UNSIGNED_BYTE_2_3_3_REV, GLU_UNSIGNED_SHORT_5_6_5, GLU_UNSIGNED_SHORT_5_6_5_REV,GLU_UNSIGNED_SHORT_4_4_4_4, GLU_UNSIGNED_SHORT_4_4_4_4_REV, GLU_UNSIGNED_SHORT_5_5_5_1, GLU_UNSIGNED_SHORT_1_5_5_5_REV, GLU_UNSIGNED_INT_8_8_8_8, GLU_UNSIGNED_INT_8_8_8_8_REV, GLU_UNSIGNED_INT_10_10_10_2, or GLU_UNSIGNED_INT_2_10_10_10_REV.
level
Specifies the mipmap level of the image data.
base
Specifies the minimum mipmap level to pass to glTexImage2D.
max
Specifies the maximum mipmap level to pass to glTexImage2D.
data
Specifies a pointer to the image data in memory.

Description

gluBuild2DMipmapLevels builds a subset of prefiltered two-dimensional texture maps of decreasing resolutions called a mipmap. This is used for the antialiasing of texture mapped primitives.
A return value of zero indicates success, otherwise a GLU error code is returned (see gluErrorString).
A series of mipmap levels from base to max is built by decimating data in half along both dimensions until size 1 × 1 is reached. At each level, each texel in the halved mipmap level is an average of the corresponding four texels in the larger mipmap level. (In the case of rectangular images, the decimation will ultimately reach an N × 1 or 1 × N configuration. Here, two texels are averaged instead.) glTexImage2D is called to load these mipmap levels from base to max. If max is larger than the highest mipmap level for the texture of the specified size, then a GLU error code is returned (see gluErrorString) and nothing is loaded. (gluBuild2DMipmapLevels)
For example, if level is 2 and width is 16 and height is 8, the following levels are possible: 16 × 8 , 8 × 4 , 4 × 2 , 2 × 1 , 1 × 1 . These correspond to levels 2 through 6 respectively. If base is 3 and max is 5, then only mipmap levels 8 × 4 , 4 × 2 , and 2 × 1 are loaded. However, if max is 7, then an error is returned and nothing is loaded since max is larger than the highest mipmap level which is, in this case, 6.
The highest mipmap level can be derived from the formula log 2  max  width height × 2 level .
See the glTexImage1D reference page for a description of the acceptable values for format parameter. See the glDrawPixels reference page for a description of the acceptable values for type parameter.

Notes

gluBuild2DMipmapLevels is only available if the GLU version is 1.3 or greater.
Formats GLU_BGR, and GLU_BGRA, and types GLU_UNSIGNED_BYTE_3_3_2, GLU_UNSIGNED_BYTE_2_3_3_REV, GLU_UNSIGNED_SHORT_5_6_5, GLU_UNSIGNED_SHORT_5_6_5_REV, GLU_UNSIGNED_SHORT_4_4_4_4, GLU_UNSIGNED_SHORT_4_4_4_4_REV, GLU_UNSIGNED_SHORT_5_5_5_1, GLU_UNSIGNED_SHORT_1_5_5_5_REV,GLU_UNSIGNED_INT_8_8_8_8, GLU_UNSIGNED_INT_8_8_8_8_REV, GLU_UNSIGNED_INT_10_10_10_2, and GLU_UNSIGNED_INT_2_10_10_10_REV are only available if the GL version is 1.2 or greater.

Errors

GLU_INVALID_VALUE is returned if level > base, base < 0, max < base, or max is > the highest mipmap level for data.
GLU_INVALID_VALUE is returned if width or height is < 1.
GLU_INVALID_ENUM is returned if internalFormat, format, or type is not legal.
GLU_INVALID_OPERATION is returned if type is GLU_UNSIGNED_BYTE_3_3_2 or GLU_UNSIGNED_BYTE_2_3_3_REV and format is not GLU_RGB.
GLU_INVALID_OPERATION is returned if type is GLU_UNSIGNED_SHORT_5_6_5 or GLU_UNSIGNED_SHORT_5_6_5_REV and format is not GLU_RGB.
GLU_INVALID_OPERATION is returned if type is GLU_UNSIGNED_SHORT_4_4_4_4 or GLU_UNSIGNED_SHORT_4_4_4_4_REV and format is neither GLU_RGBA nor GLU_BGRA.
GLU_INVALID_OPERATION is returned if type is GLU_UNSIGNED_SHORT_5_5_5_1 or GLU_UNSIGNED_SHORT_1_5_5_5_REV and format is neither GLU_RGBA nor GLU_BGRA.
GLU_INVALID_OPERATION is returned if type is GLU_UNSIGNED_INT_8_8_8_8 or GLU_UNSIGNED_INT_8_8_8_8_REV and format is neither GLU_RGBA nor GLU_BGRA.
GLU_INVALID_OPERATION is returned if type is GLU_UNSIGNED_INT_10_10_10_2 or GLU_UNSIGNED_INT_2_10_10_10_REV and format is neither GLU_RGBA nor GLU_BGRA.

Copyright

Copyright © 1991-2006 Silicon Graphics, Inc. This document is licensed under the SGI Free Software B License. For details, see http://oss.sgi.com/projects/FreeB/.

Example 1 - gluBuild2DMipmapLevels

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0 );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0 );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0 );
GLint ret = gluBuild2DMipmaps(GL_TEXTURE_2D, gl_InternalFormat(),
m_iWidth, m_iHeight, gl_RasterFormat(), gl_RasterType(),
&m_pSrcBitmap[0]);



------------------------------------------------------------------------------------------
Example 2


GLint ret = gluBuild2DMipmapLevels(GL_TEXTURE_2D,
gl_InternalFormat(),
m_iWidth, m_iHeight, gl_RasterFormat(), gl_RasterType(),
0, 0, 0,
&m_pSrcBitmap[0]);

gluBeginCurve example c c++ objc java

Name
gluBeginCurve — delimit a NURBS curve definition

C Specification

void gluBeginCurve(GLUnurbs*  nurb);

C Specification

void gluEndCurve(GLUnurbs*  nurb);

Parameters

nurb
Specifies the NURBS object (created with gluNewNurbsRenderer).

Description

Use gluBeginCurve to mark the beginning of a NURBS curve definition. After calling gluBeginCurve, make one or more calls to gluNurbsCurve to define the attributes of the curve. Exactly one of the calls to gluNurbsCurve must have a curve type of GLU_MAP1_VERTEX_3or GLU_MAP1_VERTEX_4. To mark the end of the NURBS curve definition, call gluEndCurve.
GL evaluators are used to render the NURBS curve as a series of line segments. Evaluator state is preserved during rendering with glPushAttrib(GLU_EVAL_BIT) and glPopAttrib(). See the glPushAttrib reference page for details on exactly what state these calls preserve.

Example of gluBeginCurve

The following commands render a textured NURBS curve with normals; texture coordinates and normals are also specified as NURBS curves:
<Example 1>
gluBeginCurve(nobj);
   gluNurbsCurve(nobj, ..., GL_MAP1_TEXTURE_COORD_2);
   gluNurbsCurve(nobj, ..., GL_MAP1_NORMAL);
   gluNurbsCurve(nobj, ..., GL_MAP1_VERTEX_4);
gluEndCurve(nobj); 
 
<Example 2> 
glColor3f(CS390_CURVE_COLOR);      /* select a drawing color     */
glLineWidth(2);                    /* select a line width        */
if(n >= 2) {                       /* draw curve only if n >= 2  */
    glShadeModel(GL_FLAT);         /* select a shading model     */
    glEnable(GL_MAP1_VERTEX_3);    /* activate mapping and do it */
    gluBeginCurve(theNurbs);       /* start NURBS curve drawing  */
    gluNurbsCurve(theNurbs,        /* draw a NURBS curve         */
                  m,               /* # of knots                 */
                  &knot_v[0],      /* knot vector                */
                  3,               /* u stride                   */
                  &points_v[0][0], /* control points array       */
                  p + 1,           /* order = degree + 1         */
                  GL_MAP1_VERTEX_3);    /* do it as here         */
    gluEndCurve(theNurbs);         /* end of NURBS curve drawing */
}  

Copyright

Copyright © 1991-2006 Silicon Graphics, Inc. This document is licensed under the SGI Free Software B License. For details, see http://oss.sgi.com/projects/FreeB/.



glCullFace example c c++ java objc

Name
glCullFace — specify whether front- or back-facing facets can be culled

C Specification

void glCullFace(GLenum  mode);

Parameters

mode
Specifies whether front- or back-facing facets are candidates for culling. Symbolic constants GL_FRONT, GL_BACK, and GL_FRONT_AND_BACK are accepted. The initial value is GL_BACK.

Description

glCullFace specifies whether front- or back-facing facets are culled (as specified by mode) when facet culling is enabled. Facet culling is initially disabled. To enable and disable facet culling, call the glEnable and glDisable commands with the argumentGL_CULL_FACE. Facets include triangles, quadrilaterals, polygons, and rectangles.
glFrontFace specifies which of the clockwise and counterclockwise facets are front-facing and back-facing. See glFrontFace.

Notes

If mode is GL_FRONT_AND_BACK, no facets are drawn, but other primitives such as points and lines are drawn.

Errors

GL_INVALID_ENUM is generated if mode is not an accepted value.
GL_INVALID_OPERATION is generated if glCullFace is executed between the execution of glBegin and the corresponding execution of glEnd.

Associated Gets

glIsEnabled with argument GL_CULL_FACE
glGet with argument GL_CULL_FACE_MODE

See Also

glEnable, glFrontFace

Copyright

Copyright © 1991-2006 Silicon Graphics, Inc. This document is licensed under the SGI Free Software B License. For details, see http://oss.sgi.com/projects/FreeB/.

Example

package com.minkandroid.ui.sample.work;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import com.minkandroid.ui.sample.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.opengl.GLSurfaceView;
import android.opengl.GLUtils;
class COpenGLRenderTest implements GLSurfaceView.Renderer {
public class TestRect
{
private IntBuffer mVertexBuffer;
private IntBuffer mColorBuffer;
private ByteBuffer mIndexBuffer;
private FloatBuffer mTexBuffer;
public TestRect()
{
int one = 0x40000;
int vertices[] = {
-one, one, one/4, //0
one, one, one/4, //1
one, -one, one/4,//2
-one, -one, one/4//3
};
// int one = 1;
// int vertices[] = {
// -one, one, 0, //0
// one, one, 0, //1
// one, -one, 0,//2
// -one, -one, 0//3
// };

/**
* 버텍스가 반시계방향이건 아니건 그냥 버텍스와 텍스쳐는 그냥 매핑된다.
* 하지만 원이미지와 화면은 상하 반전해야한다.
* V --> Texture
* 0--1 3--2
* | | | |
* 3--2 0--1
*/
float verticesTex[] = {
(float)0, (float)0,
(float)1, (float)0,
(float)1, (float)1,
(float)0, (float)1
};
// int colors[] = {
// 0, 0, 0, one,
// one, 0, 0, one,
// one, one, 0, one,
// 0, one, 0, one
// };
int colors[] = {
0, 0, 0, 0x1000,
0x1000, 0, 0, 0x1000,
0x1000, 0x1000, 0, 0x1000,
0, 0x1000, 0, 0x1000
};
byte indices[] = {
0, 1, 3, 1, 2, 3
};
ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length*4);
vbb.order(ByteOrder.nativeOrder());
mVertexBuffer = vbb.asIntBuffer();
mVertexBuffer.put(vertices);
mVertexBuffer.position(0);

ByteBuffer cbb = ByteBuffer.allocateDirect(colors.length*4);
cbb.order(ByteOrder.nativeOrder());
mColorBuffer = cbb.asIntBuffer();
mColorBuffer.put(colors);
mColorBuffer.position(0);

mIndexBuffer = ByteBuffer.allocateDirect(indices.length);
mIndexBuffer.put(indices);
mIndexBuffer.position(0);
ByteBuffer fbb = ByteBuffer.allocateDirect(verticesTex.length*4);
fbb.order(ByteOrder.nativeOrder());
mTexBuffer = fbb.asFloatBuffer();
mTexBuffer.put(verticesTex);
mTexBuffer.position(0);
}
public void draw(GL10 gl)
{
//시계방향으로 감기
gl.glFrontFace(GL10.GL_CW);
// which one should NOT be drawn
gl.glCullFace(GL10.GL_BACK);

//3: 배열의 3개씩 읽어온다.
gl.glVertexPointer(3, GL10.GL_FIXED, 0, mVertexBuffer);
//4: 배열의 4개씩 읽어온다.
gl.glColorPointer(4, GL10.GL_FIXED, 0, mColorBuffer);
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mTexBuffer);
//삼각형형태로 그린다. 6:인덱스의수
gl.glDrawElements(GL10.GL_TRIANGLES, 6, GL10.GL_UNSIGNED_BYTE, mIndexBuffer);
}
}

TestRect m_rtTest;
int[] m_texturesID;
Context m_context;
public COpenGLRenderTest(Context context)
{
m_rtTest = new TestRect();
m_context = context;
}
@Override
public void onDrawFrame(GL10 gl)
{
//텍스쳐지원
//gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE,GL10.GL_MODULATE);
//화면을 클리어한다. (컬러와 Depth 클리어 한다)
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(GL10.GL_MODELVIEW); //투영을 위한 행렬을 정의 한다.
gl.glLoadIdentity(); //좌표계 초기화를 한다.
gl.glTranslatef(0, 0, -2.0f); //이동
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); //정점 Array 사용할 있게 선언한다.
gl.glEnableClientState(GL10.GL_COLOR_ARRAY); //Color Array 사용할 있게 선언한다.
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
//gl.glActiveTexture(GL10.GL_TEXTURE0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, m_texturesID[0]);
//gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,GL10.GL_REPEAT);
//gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,GL10.GL_REPEAT);
m_rtTest.draw(gl);
}

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
gl.glViewport(0, 0, width, height); //뷰포트를 정의 한다.
float ratio = (float) width / height;
gl.glMatrixMode(GL10.GL_PROJECTION); //투영을 위한 행렬을 정의 한다.
gl.glLoadIdentity(); //좌표계 초기화를 한다.
gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10); //투영을 비율을 정의 한다. 1:화면비율(w/h)
float diam = 8;
float zNear = 10.f;
float zFar = zNear + diam;
int cx = 0, cy = 0;
float left = cx - diam;
float right = cx + diam;
float bottom = cy - diam;
float top = cy + diam;



if ( ratio < 1.0 ) { // window taller than wide
bottom /= ratio;
top /= ratio;
} else {
left *= ratio;
right *= ratio;
}
//Z 축으로 세모가 나열되어 있다고 가정하여 앞에서 바라 봤을 경우 재일 세모만 보인다.
gl.glOrthof(left, right, bottom, top, zNear, zFar);
//Z 축으로 세모가 나열되어 있다고 가정하여 앞에서 바라 봤을 경우, Z축으로 작아지면서 나열되는 세모들이 보인다.
// gl.glFrustumf(left, right, bottom, top, -zNear, zFar);
//gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10); //투영을 비율을 정의 한다. 1:화면비율(w/h)
}

@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config)
{
gl.glDisable(GL10.GL_DITHER); //움직임 효과를 빠르게 해준다. (흔들림) 꺼둔다.
//드라이버에 원근보정을 가장 빠르게 요청한다. 하드웨어에 따라서 달라진다.
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,GL10.GL_FASTEST);
gl.glClearColor(.5f, .5f, .5f, 1);
gl.glEnable(GL10.GL_CULL_FACE); //폴리곤 추려 내기.
gl.glShadeModel(GL10.GL_SMOOTH);
//물체를 하나 그리고 앞쪽으로 물체를 하나 그리면 처음에 그렸던 물체에 나중에 그린 물체가 가리는 현상이 생길 있는다.
gl.glEnable(GL10.GL_DEPTH_TEST);
//텟스쳐 맵정의를 한다.
gl.glEnable(GL10.GL_TEXTURE_2D);
//테스처를 특정 별명을 붙혀준다.
m_texturesID = new int[1];
gl.glGenTextures(1, m_texturesID, 0);
// 별명에 텟스처를 바인드한다.
gl.glBindTexture(GL10.GL_TEXTURE_2D, m_texturesID[0]);
//축소시 가장가까운 픽셀을 참조하여 축소를 한다.
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,GL10.GL_NEAREST);
//확대시 선형으로 확대를 하여 고르게 한다.
gl.glTexParameterf(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_MAG_FILTER,GL10.GL_LINEAR);
//경계선을 고르게 한다.
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,GL10.GL_CLAMP_TO_EDGE);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,GL10.GL_CLAMP_TO_EDGE);
//GL_REPLACE 텍스처를 물체에 입힌다.
gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE,GL10.GL_REPLACE);
InputStream is = m_context.getResources().openRawResource(R.drawable.test_doc);
Bitmap bitmap;
try {
bitmap = BitmapFactory.decodeStream(is);
}
finally
{
try
{
is.close();
}
catch(IOException e)
{
// Ignore.
}
}
//텍스쳐를 읽어들인다.
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
bitmap.recycle();
}

}