List of usage examples for org.lwjgl.opengl GL11 glTexCoord2f
public static native void glTexCoord2f(@NativeType("GLfloat") float s, @NativeType("GLfloat") float t);
From source file:net.phatcode.rel.multimedia.Graphics.java
License:Open Source License
private void drawSprite(float x, float y, float r, float g, float b, float a, int flipmode, SpriteGL sprite) { flipmode = getflipMode(flipmode);/*from ww w . j ava 2 s . co m*/ float x2 = x + sprite.width; float y2 = y + sprite.height; float u1 = ((flipmode & SpriteGL.FLIP_H) == 0) ? sprite.u1 : sprite.u2; float v1 = ((flipmode & SpriteGL.FLIP_V) == 0) ? sprite.v1 : sprite.v2; float u2 = ((flipmode & SpriteGL.FLIP_H) == 0) ? sprite.u2 : sprite.u1; float v2 = ((flipmode & SpriteGL.FLIP_V) == 0) ? sprite.v2 : sprite.v1; if (sprite.textureID != currentTexture) { GL11.glBindTexture(GL11.GL_TEXTURE_2D, sprite.textureID); currentTexture = sprite.textureID; } GL11.glColor4f(r, g, b, a); GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(u1, v1); GL11.glVertex2f(x, y); GL11.glTexCoord2f(u1, v2); GL11.glVertex2f(x, y2); GL11.glTexCoord2f(u2, v2); GL11.glVertex2f(x2, y2); GL11.glTexCoord2f(u2, v1); GL11.glVertex2f(x2, y); GL11.glEnd(); }
From source file:net.phatcode.rel.multimedia.Graphics.java
License:Open Source License
private void drawTransformedSprite(float x, float y, float angle, float scaleX, float scaleY, int flipmode, SpriteGL sprite) {/*from w w w .j a v a2 s . c o m*/ flipmode = getflipMode(flipmode); float s_half_x = sprite.width / 2.0f; float s_half_y = sprite.height / 2.0f; float x1 = -s_half_x; float y1 = -s_half_y; float u1 = ((flipmode & SpriteGL.FLIP_H) == 0) ? sprite.u1 : sprite.u2; float v1 = ((flipmode & SpriteGL.FLIP_V) == 0) ? sprite.v1 : sprite.v2; float u2 = ((flipmode & SpriteGL.FLIP_H) == 0) ? sprite.u2 : sprite.u1; float v2 = ((flipmode & SpriteGL.FLIP_V) == 0) ? sprite.v2 : sprite.v1; if (sprite.textureID != currentTexture) { GL11.glBindTexture(GL11.GL_TEXTURE_2D, sprite.textureID); currentTexture = sprite.textureID; } GL11.glPushMatrix(); GL11.glTranslatef(x, y, 0.0f); GL11.glScalef(scaleX, scaleY, 1.0f); GL11.glRotatef(angle, 0.0f, 0.0f, 1.0f); GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(u1, v1); GL11.glVertex2f(x1, y1); GL11.glTexCoord2f(u1, v2); GL11.glVertex2f(x1, s_half_y); GL11.glTexCoord2f(u2, v2); GL11.glVertex2f(s_half_x, s_half_y); GL11.glTexCoord2f(u2, v1); GL11.glVertex2f(s_half_x, y1); GL11.glEnd(); GL11.glPopMatrix(); }
From source file:net.phatcode.rel.multimedia.Graphics.java
License:Open Source License
private void drawTransformedSprite(float x, float y, float angle, float scaleX, float scaleY, float r, float g, float b, float a, int flipmode, SpriteGL sprite) { flipmode = getflipMode(flipmode);/* www. j av a 2 s. c o m*/ float s_half_x = sprite.width / 2.0f; float s_half_y = sprite.height / 2.0f; float x1 = -s_half_x; float y1 = -s_half_y; float u1 = ((flipmode & SpriteGL.FLIP_H) == 0) ? sprite.u1 : sprite.u2; float v1 = ((flipmode & SpriteGL.FLIP_V) == 0) ? sprite.v1 : sprite.v2; float u2 = ((flipmode & SpriteGL.FLIP_H) == 0) ? sprite.u2 : sprite.u1; float v2 = ((flipmode & SpriteGL.FLIP_V) == 0) ? sprite.v2 : sprite.v1; if (sprite.textureID != currentTexture) { GL11.glBindTexture(GL11.GL_TEXTURE_2D, sprite.textureID); currentTexture = sprite.textureID; } GL11.glColor4f(r, g, b, a); GL11.glPushMatrix(); GL11.glTranslatef(x, y, 0.0f); GL11.glScalef(scaleX, scaleY, 1.0f); GL11.glRotatef(angle, 0.0f, 0.0f, 1.0f); GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(u1, v1); GL11.glVertex2f(x1, y1); GL11.glTexCoord2f(u1, v2); GL11.glVertex2f(x1, s_half_y); GL11.glTexCoord2f(u2, v2); GL11.glVertex2f(s_half_x, s_half_y); GL11.glTexCoord2f(u2, v1); GL11.glVertex2f(s_half_x, y1); GL11.glEnd(); GL11.glPopMatrix(); }
From source file:net.phatcode.rel.multimedia.Graphics.java
License:Open Source License
public void drawSpriteOnLine(int x1, int y1, int x2, int y2, int width, int type) { SpriteGL sprite = glowImages.getSprite(type % glowImages.getNumImages()); // Only change active texture when there is a need // Speeds up the rendering by batching textures if (sprite.textureID != currentTexture) { GL11.glBindTexture(GL11.GL_TEXTURE_2D, sprite.textureID); currentTexture = sprite.textureID; }/*from ww w .jav a 2 s. co m*/ float u1 = sprite.u1; float v1 = sprite.v1; float u2 = sprite.u2; float v2 = sprite.v2; float uh = (u1 + u2) / 2.0f; float nx, ny; nx = -(y2 - y1); ny = (x2 - x1); float leng; leng = (float) Math.sqrt(nx * nx + ny * ny); nx = nx / leng; ny = ny / leng; nx *= width / 2.0; ny *= width / 2.0; float lx1, ly1, lx2, ly2, lx3, ly3, lx4, ly4; lx1 = x2 + nx; ly1 = y2 + ny; lx2 = x2 - nx; ly2 = y2 - ny; lx3 = x1 - nx; ly3 = y1 - ny; lx4 = x1 + nx; ly4 = y1 + ny; // MAIN GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(uh, v1); GL11.glVertex3f(lx1, ly1, 0.0f); GL11.glTexCoord2f(uh, v2); GL11.glVertex3f(lx2, ly2, 0.0f); GL11.glTexCoord2f(uh, v2); GL11.glVertex3f(lx3, ly3, 0.0f); GL11.glTexCoord2f(uh, v1); GL11.glVertex3f(lx4, ly4, 0.0f); GL11.glEnd(); //RIGHT float lx5, ly5, lx6, ly6, vx, vy; vx = (x2 - x1); vy = (y2 - y1); leng = (float) Math.sqrt(vx * vx + vy * vy); vx = vx / leng; vy = vy / leng; vx *= width / 2.0; vy *= width / 2.0; lx5 = lx1 + vx; ly5 = ly1 + vy; lx6 = lx2 + vx; ly6 = ly2 + vy; GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(uh, v1); GL11.glVertex3f(lx1, ly1, 0.0f); GL11.glTexCoord2f(u2, v1); GL11.glVertex3f(lx5, ly5, 0.0f); GL11.glTexCoord2f(u2, v2); GL11.glVertex3f(lx6, ly6, 0.0f); GL11.glTexCoord2f(uh, v2); GL11.glVertex3f(lx2, ly2, 0.0f); GL11.glEnd(); // LEFT lx5 = lx4 - vx; ly5 = ly4 - vy; lx6 = lx3 - vx; ly6 = ly3 - vy; GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(uh, v1); GL11.glVertex3f(lx4, ly4, 0.0f); GL11.glTexCoord2f(uh, v2); GL11.glVertex3f(lx3, ly3, 0.0f); GL11.glTexCoord2f(u2, v2); GL11.glVertex3f(lx6, ly6, 0.0f); GL11.glTexCoord2f(u2, v1); GL11.glVertex3f(lx5, ly5, 0.0f); GL11.glEnd(); }
From source file:net.phatcode.rel.multimedia.Graphics.java
License:Open Source License
public void drawSpriteOnLine(int x1, int y1, int x2, int y2, int width, int type, float r, float g, float b, float a) { SpriteGL sprite = glowImages.getSprite(type % glowImages.getNumImages()); // Only change active texture when there is a need // Speeds up the rendering by batching textures if (sprite.textureID != currentTexture) { GL11.glBindTexture(GL11.GL_TEXTURE_2D, sprite.textureID); currentTexture = sprite.textureID; }//www .j av a2 s . co m GL11.glColor4f(r, g, b, a); float u1 = sprite.u1; float v1 = sprite.v1; float u2 = sprite.u2; float v2 = sprite.v2; float uh = (u1 + u2) / 2.0f; float nx, ny; nx = -(y2 - y1); ny = (x2 - x1); float leng; leng = (float) Math.sqrt(nx * nx + ny * ny); nx = nx / leng; ny = ny / leng; nx *= width / 2.0; ny *= width / 2.0; float lx1, ly1, lx2, ly2, lx3, ly3, lx4, ly4; lx1 = x2 + nx; ly1 = y2 + ny; lx2 = x2 - nx; ly2 = y2 - ny; lx3 = x1 - nx; ly3 = y1 - ny; lx4 = x1 + nx; ly4 = y1 + ny; // MAIN GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(uh, v1); GL11.glVertex3f(lx1, ly1, 0.0f); GL11.glTexCoord2f(uh, v2); GL11.glVertex3f(lx2, ly2, 0.0f); GL11.glTexCoord2f(uh, v2); GL11.glVertex3f(lx3, ly3, 0.0f); GL11.glTexCoord2f(uh, v1); GL11.glVertex3f(lx4, ly4, 0.0f); GL11.glEnd(); //RIGHT float lx5, ly5, lx6, ly6, vx, vy; vx = (x2 - x1); vy = (y2 - y1); leng = (float) Math.sqrt(vx * vx + vy * vy); vx = vx / leng; vy = vy / leng; vx *= width / 2.0; vy *= width / 2.0; lx5 = lx1 + vx; ly5 = ly1 + vy; lx6 = lx2 + vx; ly6 = ly2 + vy; GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(uh, v1); GL11.glVertex3f(lx1, ly1, 0.0f); GL11.glTexCoord2f(u2, v1); GL11.glVertex3f(lx5, ly5, 0.0f); GL11.glTexCoord2f(u2, v2); GL11.glVertex3f(lx6, ly6, 0.0f); GL11.glTexCoord2f(uh, v2); GL11.glVertex3f(lx2, ly2, 0.0f); GL11.glEnd(); // LEFT lx5 = lx4 - vx; ly5 = ly4 - vy; lx6 = lx3 - vx; ly6 = ly3 - vy; GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(uh, v1); GL11.glVertex3f(lx4, ly4, 0.0f); GL11.glTexCoord2f(uh, v2); GL11.glVertex3f(lx3, ly3, 0.0f); GL11.glTexCoord2f(u2, v2); GL11.glVertex3f(lx6, ly6, 0.0f); GL11.glTexCoord2f(u2, v1); GL11.glVertex3f(lx5, ly5, 0.0f); GL11.glEnd(); }
From source file:net.phatcode.rel.multimedia.Graphics.java
License:Open Source License
private void drawScrolledSprite(float x, float y, float scaleX, float scaleY, float u, float v, int flipmode, SpriteGL sprite) {/*w ww. j a v a 2s . co m*/ flipmode = getflipMode(flipmode); float x2 = x + sprite.width; float y2 = y + sprite.height; float u1 = ((flipmode & SpriteGL.FLIP_H) == 0) ? sprite.u1 : sprite.u2; float v1 = ((flipmode & SpriteGL.FLIP_V) == 0) ? sprite.v1 : sprite.v2; float u2 = ((flipmode & SpriteGL.FLIP_H) == 0) ? sprite.u2 : sprite.u1; float v2 = ((flipmode & SpriteGL.FLIP_V) == 0) ? sprite.v2 : sprite.v1; if (sprite.textureID != currentTexture) { GL11.glBindTexture(GL11.GL_TEXTURE_2D, sprite.textureID); currentTexture = sprite.textureID; } GL11.glPushMatrix(); GL11.glScalef(scaleX, scaleY, 1.0f); GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(u1 + u, v1 + v); GL11.glVertex2f(x, y); GL11.glTexCoord2f(u1 + u, v2 + v); GL11.glVertex2f(x, y2); GL11.glTexCoord2f(u2 + u, v2 + v); GL11.glVertex2f(x2, y2); GL11.glTexCoord2f(u2 + u, v1 + v); GL11.glVertex2f(x2, y); GL11.glEnd(); GL11.glPopMatrix(); }
From source file:net.phatcode.rel.multimedia.Graphics.java
License:Open Source License
private void drawScrolledSprite(float x, float y, float scaleX, float scaleY, float u, float v, float r, float g, float b, float a, int flipmode, SpriteGL sprite) { flipmode = getflipMode(flipmode);//w w w . j a v a2s . c o m float x2 = x + sprite.width; float y2 = y + sprite.height; float u1 = ((flipmode & SpriteGL.FLIP_H) == 0) ? sprite.u1 : sprite.u2; float v1 = ((flipmode & SpriteGL.FLIP_V) == 0) ? sprite.v1 : sprite.v2; float u2 = ((flipmode & SpriteGL.FLIP_H) == 0) ? sprite.u2 : sprite.u1; float v2 = ((flipmode & SpriteGL.FLIP_V) == 0) ? sprite.v2 : sprite.v1; if (sprite.textureID != currentTexture) { GL11.glBindTexture(GL11.GL_TEXTURE_2D, sprite.textureID); currentTexture = sprite.textureID; } GL11.glColor4f(r, g, b, a); GL11.glPushMatrix(); GL11.glScalef(scaleX, scaleY, 1.0f); GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(u1 + u, v1 + v); GL11.glVertex2f(x, y); GL11.glTexCoord2f(u1 + u, v2 + v); GL11.glVertex2f(x, y2); GL11.glTexCoord2f(u2 + u, v2 + v); GL11.glVertex2f(x2, y2); GL11.glTexCoord2f(u2 + u, v1 + v); GL11.glVertex2f(x2, y); GL11.glEnd(); GL11.glPopMatrix(); }
From source file:net.shadowmage.ancientwarfare.core.model.PrimitiveBox.java
License:Open Source License
@Override protected void renderPrimitive(float tw, float th) { float px = 1.f / tw; float py = 1.f / th; float w = (float) Math.ceil((x2 - x1) * 16.f); float h = (float) Math.ceil((y2 - y1) * 16.f); float l = (float) Math.ceil((z2 - z1) * 16.f); float ty = this.ty(); float tx = this.tx(); float tx1, ty1, tx2, ty2; if (w < 1) { w = 1;/*w w w. j a va 2 s .c o m*/ } if (h < 1) { h = 1; } if (l < 1) { l = 1; } //render the cube. only called a single time when building the display list for a piece if (rx != 0) { GL11.glRotatef(rx, 1, 0, 0); } if (ry != 0) { GL11.glRotatef(ry, 0, 1, 0); } if (rz != 0) { GL11.glRotatef(rz, 0, 0, 1); } GL11.glBegin(GL11.GL_QUADS); //front side tx1 = (tx + l) * px; ty1 = (th - (ty + l + h)) * py; tx2 = (tx + l + w) * px; ty2 = (th - (ty + l)) * py; ty1 = 1.f - ty1; ty2 = 1.f - ty2; GL11.glNormal3f(0, 0, 1); GL11.glTexCoord2f(tx1, ty1); GL11.glVertex3f(x1, y1, z2); GL11.glTexCoord2f(tx2, ty1); GL11.glVertex3f(x2, y1, z2); GL11.glTexCoord2f(tx2, ty2); GL11.glVertex3f(x2, y2, z2); GL11.glTexCoord2f(tx1, ty2); GL11.glVertex3f(x1, y2, z2); ////rear side tx1 = (tx + l + l + w) * px; ty1 = (th - (ty + l + h)) * py; tx2 = (tx + l + w + l + w) * px; ty2 = (th - (ty + l)) * py; ty1 = 1.f - ty1; ty2 = 1.f - ty2; GL11.glNormal3f(0, 0, -1); GL11.glTexCoord2f(tx1, ty1); GL11.glVertex3f(x2, y1, z1); GL11.glTexCoord2f(tx2, ty1); GL11.glVertex3f(x1, y1, z1); GL11.glTexCoord2f(tx2, ty2); GL11.glVertex3f(x1, y2, z1); GL11.glTexCoord2f(tx1, ty2); GL11.glVertex3f(x2, y2, z1); //right side tx1 = (tx + l + w) * px; ty1 = (th - (ty + l + h)) * py; tx2 = (tx + l + w + l) * px; ty2 = (th - (ty + l)) * py; ty1 = 1.f - ty1; ty2 = 1.f - ty2; GL11.glNormal3f(-1, 0, 0); GL11.glTexCoord2f(tx1, ty1); GL11.glVertex3f(x1, y1, z1); GL11.glTexCoord2f(tx2, ty1); GL11.glVertex3f(x1, y1, z2); GL11.glTexCoord2f(tx2, ty2); GL11.glVertex3f(x1, y2, z2); GL11.glTexCoord2f(tx1, ty2); GL11.glVertex3f(x1, y2, z1); // //left side tx1 = (tx) * px; ty1 = (th - (ty + l + h)) * py; tx2 = (tx + l) * px; ty2 = (th - (ty + l)) * py; ty1 = 1.f - ty1; ty2 = 1.f - ty2; GL11.glNormal3f(1, 0, 0); GL11.glTexCoord2f(tx1, ty1); GL11.glVertex3f(x2, y1, z2); GL11.glTexCoord2f(tx2, ty1); GL11.glVertex3f(x2, y1, z1); GL11.glTexCoord2f(tx2, ty2); GL11.glVertex3f(x2, y2, z1); GL11.glTexCoord2f(tx1, ty2); GL11.glVertex3f(x2, y2, z2); // //top side tx1 = (tx + l) * px; ty1 = (th - (ty + l)) * py; tx2 = (tx + l + w) * px; ty2 = (th - (ty)) * py; ty1 = 1.f - ty1; ty2 = 1.f - ty2; GL11.glNormal3f(0, 1, 0); GL11.glTexCoord2f(tx1, ty1); GL11.glVertex3f(x2, y2, z1); GL11.glTexCoord2f(tx2, ty1); GL11.glVertex3f(x1, y2, z1); GL11.glTexCoord2f(tx2, ty2); GL11.glVertex3f(x1, y2, z2); GL11.glTexCoord2f(tx1, ty2); GL11.glVertex3f(x2, y2, z2); // //bottom side tx1 = (tx + l + w) * px; ty1 = (th - (ty + l)) * py; tx2 = (tx + l + w + w) * px; ty2 = (th - (ty)) * py; ty1 = 1.f - ty1; ty2 = 1.f - ty2; GL11.glNormal3f(0, -1, 0); GL11.glTexCoord2f(tx1, ty1); GL11.glVertex3f(x2, y1, z2); GL11.glTexCoord2f(tx2, ty1); GL11.glVertex3f(x1, y1, z2); GL11.glTexCoord2f(tx2, ty2); GL11.glVertex3f(x1, y1, z1); GL11.glTexCoord2f(tx1, ty2); GL11.glVertex3f(x2, y1, z1); GL11.glEnd(); }
From source file:net.shadowmage.ancientwarfare.core.model.PrimitiveQuad.java
License:Open Source License
@Override protected void renderPrimitive(float tw, float th) { float px = 1.f / tw; float py = 1.f / th; float w = (x2 - x1) * 16.f; float l = 1.f;//TODO fix this for proper texture handling float h = (y2 - y1) * 16.f; float ty = this.ty(); float tx = this.tx(); float tx1, ty1, tx2, ty2; //render the cube. only called a single time when building the display list for a piece if (rx != 0) { GL11.glRotatef(rx, 1, 0, 0);/*w ww.j a v a 2s . c om*/ } if (ry != 0) { GL11.glRotatef(ry, 0, 1, 0); } if (rz != 0) { GL11.glRotatef(rz, 0, 0, 1); } GL11.glBegin(GL11.GL_QUADS); //front side tx1 = (tx + l) * px; ty1 = (th - (ty + l + h)) * py; tx2 = (tx + l + w) * px; ty2 = (th - (ty + l)) * py; GL11.glNormal3f(0, 0, 1); GL11.glTexCoord2f(tx1, ty1); GL11.glVertex3f(x1, y1, 0.f); GL11.glTexCoord2f(tx2, ty1); GL11.glVertex3f(x2, y1, 0.f); GL11.glTexCoord2f(tx2, ty2); GL11.glVertex3f(x2, y2, 0.f); GL11.glTexCoord2f(tx1, ty2); GL11.glVertex3f(x1, y2, 0.f); GL11.glEnd(); }
From source file:net.shadowmage.ancientwarfare.core.model.PrimitiveTriangle.java
License:Open Source License
@Override protected void renderPrimitive(float tw, float th) { if (rx != 0) { GL11.glRotatef(rx, 1, 0, 0);// ww w . j av a 2 s . c o m } if (ry != 0) { GL11.glRotatef(ry, 0, 1, 0); } if (rz != 0) { GL11.glRotatef(rz, 0, 0, 1); } float px = 1.f / tw; float py = 1.f / th; float u1, v1, u2, v2, u3, v3; u1 = this.u1 * px + this.tx() * px; u2 = this.u2 * px + this.tx() * px; u3 = this.u3 * px + this.tx() * px; v1 = this.v1 * py + this.ty() * py; v2 = this.v2 * py + this.ty() * py; v3 = this.v3 * py + this.ty() * py; GL11.glBegin(GL11.GL_TRIANGLE_STRIP); GL11.glNormal3f(normalX, normalY, normalZ); GL11.glTexCoord2f(u1, v1); GL11.glVertex3f(x1, y1, z1); GL11.glTexCoord2f(u2, v2); GL11.glVertex3f(x2, y2, z2); GL11.glTexCoord2f(u3, v3); GL11.glVertex3f(x3, y3, z3); GL11.glEnd(); }