JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
OneTriangle.java
Go to the documentation of this file.
1/**
2 * Copyright 2010 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.opengl.test.junit.jogl.demos.es1;
30
31import com.jogamp.opengl.GL;
32import com.jogamp.opengl.GL2ES1;
33import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
34import com.jogamp.opengl.glu.GLU;
35import com.jogamp.opengl.glu.gl2es1.GLUgl2es1;
36
37import com.jogamp.opengl.util.ImmModeSink;
38
39/**
40 * A utility class to encapsulate drawing a single triangle for unit tests.
41 * @author Wade Walker
42 */
43public class OneTriangle {
44
45 public static void setup( final GL2ES1 gl, final int width, final int height ) {
47 gl.glLoadIdentity();
48
49 // coordinate system origin at lower left with width and height same as the window
50 final GLU glu = new GLUgl2es1();
51 glu.gluOrtho2D( 0.0f, width, 0.0f, height );
52
54 gl.glLoadIdentity();
55
56 gl.glViewport( 0, 0, width, height );
57 }
58
59 public static void render( final GL2ES1 gl, final int width, final int height) {
61
62 // draw a triangle filling the window
63 gl.glLoadIdentity();
64
65 final ImmModeSink immModeSink = ImmModeSink.createFixed(3*3,
66 3, GL.GL_FLOAT, // vertex
67 3, GL.GL_FLOAT, // color
68 0, GL.GL_FLOAT, // normal
69 0, GL.GL_FLOAT, // texCoords
71 immModeSink.glBegin(GL.GL_TRIANGLES);
72 immModeSink.glColor3f( 1, 0, 0 );
73 immModeSink.glVertex2f( 0, 0 );
74 immModeSink.glColor3f( 0, 1, 0 );
75 immModeSink.glVertex2f( width, 0 );
76 immModeSink.glColor3f( 0, 0, 1 );
77 immModeSink.glVertex2f( width / 2f, height );
78 immModeSink.glEnd(gl, true);
79 }
80}
Provides access to the OpenGL Utility Library (GLU).
Definition: GLU.java:43
void gluOrtho2D(float left, float right, float bottom, float top)
Definition: GLU.java:1358
A utility class to encapsulate drawing a single triangle for unit tests.
static void setup(final GL2ES1 gl, final int width, final int height)
static void render(final GL2ES1 gl, final int width, final int height)
final void glVertex2f(final float x, final float y)
static ImmModeSink createFixed(final int initialElementCount, final int vComps, final int vDataType, final int cComps, final int cDataType, final int nComps, final int nDataType, final int tComps, final int tDataType, final int glBufferUsage)
Uses a GL2ES1, or ES2 fixed function emulation immediate mode sink.
final void glColor3f(final float x, final float y, final float z)
final void glEnd(final GL gl)
static final int GL_STATIC_DRAW
GL_VERSION_1_5, GL_ES_VERSION_2_0, GL_VERSION_ES_1_0, GL_ARB_vertex_buffer_object Alias for: GL_STATI...
Definition: GL.java:673
static final int GL_TRIANGLES
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TRIANGLES" with expre...
Definition: GL.java:145
static final int GL_FLOAT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_FLOAT" with expressio...
Definition: GL.java:786
static final int GL_COLOR_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_COLOR_BUFFER_BIT" wit...
Definition: GL.java:390
void glClear(int mask)
Entry point to C language function: void {@native glClear}(GLbitfield mask) Part of GL_ES_VERSION_...
void glViewport(int x, int y, int width, int height)
Entry point to C language function: void {@native glViewport}(GLint x, GLint y, GLsizei width,...
Subset of OpenGL fixed function pipeline's matrix operations.
static final int GL_PROJECTION
Matrix mode projection.
static final int GL_MODELVIEW
Matrix mode modelview.
void glLoadIdentity()
Load the current matrix with the identity matrix.
void glMatrixMode(int mode)
Sets the current matrix mode.