• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0

UV Mapping: Where do the (u, v) coordinates correspond to on a square texture?

5 posts in this topic


In the above picture shown, I have a square texture of nontrivial size. Each number labeled 0 through 3 in blue represents each corner of the texture. The purple texture coordinates, labeled A through D, is given with it's texture coordinates, designated as (u, v).

Where do the purple labels A, B, C, and D corresponds to on the texture?

This is to understand the following:
1. The direction I'm mapping from (either clockwise, or counter-clockwise).
2. How the texture is mapped into the model view, either clockwise or counter-clockwise.
3. Why texture coordinates must come in pairs.
4. Why texture coordinates do not necessarily follow the basic principles of (x, y) when the texture is just a 2D texture.

Thanks in advance.

Share this post

Link to post
Share on other sites
0 = A
1 = C
2 = B
3 = D

at least in my implementations is does :)

see "u" as the x coordinate from left to right
and "v" as the y coordinate from top to bottom

Share this post

Link to post
Share on other sites
0 = A, would be the Direct3D-way of mapping the upper-left coordinate. OpenGL has coordinates inverted along the v-axis (B).

The best way to understand the relation between objectspace-vertices and their uv counterparts, is to recreate the above quad in a 3d modeling app and see how the textured quad reacts to changes (rotating, mirroring etc.) in the uv-map.

Share this post

Link to post
Share on other sites
I tried recreating them on my Android phone, with all glFrontFace() set to ClockWise, I still couldn't get why UV never flips when I intentionally flip the texture coordinates around.

I flipped A and C around, I get a front facing flipped texture.
I flipped A and B around, and I get a front facing flipped texture.
I flipped C and D, kept A and B from above, and I get a front facing normal texture.

Confused, confused, confused...


package test.es;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import javax.microedition.khronos.opengles.GL10;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.opengl.GLUtils;
public class Square {
public float angle = 0f;
private ByteBuffer indicesBuffer;
private FloatBuffer textureBuffer;
private FloatBuffer vertexBuffer;
private int[] textures = new int[1];
private float[] vertices = {
-2f, -2f, 0f, //Bottom left
2f, -2f, 0f, //bottom right
-2f, 2f, 0f, //Top left
2f, 2f, 0f //Top right
private float[] textureCoords = { //You move these rows up/down to flip textures here.
1f, 1f,
0f, 1f,
1f, 0f,
0f, 0f
private byte[] indices = {
public Square(){
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(vertices.length * 4); //sizeof(float) = 4
vertexBuffer = byteBuffer.asFloatBuffer();

byteBuffer = ByteBuffer.allocateDirect(textureCoords.length * 4);
textureBuffer = byteBuffer.asFloatBuffer();

indicesBuffer = ByteBuffer.allocateDirect(indices.length);

public void draw(GL10 gl){
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
//gl.glColor4f(0.1f, 0.4f, 0.9f, 1.0f);
//gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);
gl.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_BYTE, indicesBuffer);
angle -= 0.2f;

public void loadTexture(GL10 gl, Context c){
InputStream input = c.getResources().openRawResource(R.drawable.ic_launcher);
Bitmap bitmap = null;
bitmap = BitmapFactory.decodeStream(input);
finally {
try {
input = null;
catch(IOException e) {
gl.glGenTextures(1, textures, 0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);

Share this post

Link to post
Share on other sites
Keep in mind that because you've set the FrontFace state to
[left][size=3].[color=#000000]GL_CW", you're actually viewing triangles from the backside (a[/color][/size]s you've assigned indices in counterclockwise order).[/left] Edited by eppo

Share this post

Link to post
Share on other sites
So, does indices in Direct3D and OpenGL follow differently on a 2D Cartesian coordinates (where positive X is upwards, and positive Y is rightwards)?

As in:

For indices 0 through 3, by following the above picture texture coordinates, the index for (u, v) = (0, 0) is 0, the index for (u, v) = (1, 0) is 1, the index for (u, v) = (0, 1) is 2, and the index for (u, v) = (1, 1) is 3?

Hope I didn't confuse you too much.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0