JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TextureCoords.java
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
3 * Copyright (c) 2012 JogAmp Community. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * - Redistribution of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * - Redistribution in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * Neither the name of Sun Microsystems, Inc. or the names of
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * This software is provided "AS IS," without a warranty of any kind. ALL
21 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
22 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
23 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
24 * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
25 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
26 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
27 * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
28 * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
29 * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
30 * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
31 * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32 *
33 * You acknowledge that this software is not designed or intended for use
34 * in the design, construction, operation or maintenance of any nuclear
35 * facility.
36 */
37
38package com.jogamp.opengl.util.texture;
39
40/** Specifies texture coordinates for a rectangular area of a
41 texture. Note that some textures are inherently flipped vertically
42 from OpenGL's standard coordinate system. This class takes care of
43 this vertical flip so that the "bottom" and "top" coordinates may
44 sometimes be reversed. From the point of view of code rendering
45 textured polygons, it can always map the bottom and left texture
46 coordinates from the TextureCoords to the lower left point of the
47 textured polygon and achieve correct results. */
48
49public class TextureCoords {
50 // These represent the lower-left point
51 private final float left;
52 private final float bottom;
53 // These represent the upper-right point
54 private final float right;
55 private final float top;
56
57 public TextureCoords(final float left, final float bottom,
58 final float right, final float top) {
59 this.left = left;
60 this.bottom = bottom;
61 this.right = right;
62 this.top = top;
63 }
64
65 /** Transfers <code>{s * ss, t * ts}</code> from this object into the given <code>float[8+d_off]</code> in the following order:
66 * <pre>
67 * left, bottom
68 * right, bottom
69 * left, top
70 * right top
71 * </pre>
72 */
73 public float[] getST_LB_RB_LT_RT(final float[] d, final int d_off, final float ss, final float ts) {
74 d[0+d_off] = left *ss; d[1+d_off] = bottom*ts;
75 d[2+d_off] = right *ss; d[3+d_off] = bottom*ts;
76 d[4+d_off] = left *ss; d[5+d_off] = top *ts;
77 d[6+d_off] = right *ss; d[7+d_off] = top *ts;
78 return d;
79 }
80
81 /** Returns the leftmost (x) texture coordinate of this rectangle. */
82 public float left() { return left; }
83
84 /** Returns the rightmost (x) texture coordinate of this rectangle. */
85 public float right() { return right; }
86
87 /** Returns the bottommost (y) texture coordinate of this rectangle. */
88 public float bottom() { return bottom; }
89
90 /** Returns the topmost (y) texture coordinate of this rectangle. */
91 public float top() { return top; }
92
93 @Override
94 public String toString() { return "TexCoord[h: "+left+" - "+right+", v: "+bottom+" - "+top+"]"; }
95}
Specifies texture coordinates for a rectangular area of a texture.
float top()
Returns the topmost (y) texture coordinate of this rectangle.
float right()
Returns the rightmost (x) texture coordinate of this rectangle.
TextureCoords(final float left, final float bottom, final float right, final float top)
float bottom()
Returns the bottommost (y) texture coordinate of this rectangle.
float left()
Returns the leftmost (x) texture coordinate of this rectangle.
float[] getST_LB_RB_LT_RT(final float[] d, final int d_off, final float ss, final float ts)
Transfers {s * ss, t * ts} from this object into the given float[8+d_off] in the following order: