I'm trying to render an image on a basic quad, I took a look at the Space Invaders Example Game for the code, and implemented that code into mine. The image gets renderer on screen, with the right colors, but the image seems shifted. This is the image I'm trying to render:
http://img203.imageshack.us/img203/5264/testwq.png
This is how it renders:
http://img593.imageshack.us/img593/6849/test2uh.png
The image is 128x128, and so is the quad.
Here is my code:
public class RenderEngine
{
private IntBuffer intbuf = BufferUtils.createIntBuffer(1);
private ColorModel glAlphaColorModel;
private ColorModel glColorModel;
public RenderEngine()
{
this.glAlphaColorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[] { 8, 8, 8, 8 }, true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);
this.glColorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[] { 8, 8, 8, 0 }, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
}
public void bindTexture(String filename)
{
try
{
File file = new File(CivilPolitica.instance.getDir(), "resources/" + filename);
FileInputStream fis = new FileInputStream(file);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.getTexture(fis));
fis.close();
}
catch (Exception e)
{
e.printStackTrace();
System.exit(0);
}
}
private int getTexture(InputStream in)
{
try
{
GL11.glGenTextures(this.intbuf);
int id = this.intbuf.get(0);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);
BufferedImage bi = ImageIO.read(in);
int format = bi.getColorModel().hasAlpha() ? GL11.GL_RGBA : GL11.GL_RGB;
ByteBuffer texData;
WritableRaster raster;
BufferedImage texImage;
int texWidth = 2;
int texHeight = 2;
while (texWidth < bi.getWidth())
{
texWidth *= 2;
}
while (texHeight < bi.getHeight())
{
texHeight *= 2;
}
if (bi.getColorModel().hasAlpha())
{
raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, texWidth, texHeight, 4, null);
texImage = new BufferedImage(this.glAlphaColorModel, raster, false, new Hashtable<String, Object>());
}
else
{
raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, texWidth, texHeight, 3, null);
texImage = new BufferedImage(this.glColorModel, raster, false, new Hashtable<String, Object>());
}
Graphics g = texImage.getGraphics();
g.setColor(new Color(0f, 0f, 0f, 0f));
g.fillRect(0, 0, texWidth, texHeight);
g.drawImage(bi, 0, 0, null);
byte[] data = ((DataBufferByte) texImage.getRaster().getDataBuffer()).getData();
texData = ByteBuffer.allocateDirect(data.length);
texData.order(ByteOrder.nativeOrder());
texData.put(data, 0, data.length);
texData.flip();
glTexParameteri(GL11.GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
glTexParameteri(GL11.GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, bi.getWidth(), bi.getHeight(), 0, format, GL_UNSIGNED_BYTE, texData);
return id;
}
catch (Exception e)
{
e.printStackTrace();
System.exit(0);
return 0;
}
}
}
And the actual quad:
CivilPolitica.instance.renderer.bindTexture("test.png");
GL11.glPushMatrix();
GL11.glTranslatef(128, 128, 0);
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0, 0);
GL11.glVertex2i(0, 0);
GL11.glTexCoord2f(0, 127);
GL11.glVertex2i(0, 128);
GL11.glTexCoord2f(127, 127);
GL11.glVertex2i(128, 128);
GL11.glTexCoord2f(127, 0);
GL11.glVertex2i(128, 0);
GL11.glEnd();
GL11.glPopMatrix();
GL11.glTexCoord2f(0, 0);
GL11.glVertex2i(0, 0);
GL11.glTexCoord2f(0, 127);
GL11.glVertex2i(0, 128);
GL11.glTexCoord2f(127, 127);
GL11.glVertex2i(128, 128);
GL11.glTexCoord2f(127, 0);
GL11.glVertex2i(128, 0);
must be
GL11.glTexCoord2f(0.0f, 0.0f);
GL11.glVertex2i(0, 0);
GL11.glTexCoord2f(0.0f, 1.0f);
GL11.glVertex2i(0, 128);
GL11.glTexCoord2f(1.0f, 1.0f);
GL11.glVertex2i(128, 128);
GL11.glTexCoord2f(1.0f, 0.0f);
GL11.glVertex2i(128, 0);
because it are texture coordinates from 0.0f to 1.0f (0.0f ist the one side and 1.0f is the other, that way it is not resolution dependent)
Related
My skybox is displayed, but does not display the textures that I load from the image. Instead, it shows the transparent color if i set glTexImage2D how GL_RGBA, or black color if i set glTexImage2D how GL_RGB.
I am using a render with MultisampledFbo support.
My texture loading code looks like this:
private int loadSkyboxTextures(){
glGenBuffers(vbo);
glBindBuffer (GL_ARRAY_BUFFER, vbo[0]);
glBufferData(GL_ARRAY_BUFFER, POINTS, GL_STATIC_DRAW);
glBindBuffer (GL_ARRAY_BUFFER, 0);
glGenVertexArrays(vao);
glBindVertexArray(vao[0]);
glBindBuffer (GL_ARRAY_BUFFER, vbo[0]);
glVertexPointer(3, GL_FLOAT, 3 * Float.BYTES, NULL);
glTexCoordPointer (3, GL_FLOAT, 3 * Float.BYTES, NULL);
glBindBuffer (GL_ARRAY_BUFFER, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
int texID = glGenTextures();
glBindTexture(GL_TEXTURE_CUBE_MAP, texID);
for(int i = 0; i < TEXTURE_FILES.length; i++){
InputStream file = getClass().getResourceAsStream(TEXTURE_FILES[i]);
byte[] pixelData = new byte[0];
try {
pixelData = new byte[file.available()];
file.read(pixelData);
} catch (IOException e) {
e.printStackTrace();
}
ByteBuffer byteBuffer = ByteBuffer.wrap(pixelData);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, 512, 512, 0,
GL_RGB, GL_UNSIGNED_BYTE, byteBuffer);
}
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
return texID;
}
Cube Render Code:
private void drawSkybox(){
glColor4f(1,1,1,1);
glDepthMask(false);
glEnable(GL_TEXTURE_CUBE_MAP);
glBindBuffer (GL_ARRAY_BUFFER, vbo[0]);
glBindVertexArray(vao[0]);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_CUBE_MAP, texId);
glDrawArrays(GL_TRIANGLES, 0, 36);
glBindVertexArray(0);
glBindBuffer (GL_ARRAY_BUFFER, 0);
glDepthMask(true);
glDisable(GL_TEXTURE_CUBE_MAP);
}
The cube rendering call in the main render function:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
view = viewX || viewY || viewZ;
if(view)
glPushMatrix();
int rot = 180;
glDisable(GL_LIGHTING);
glViewport(0, 0, WIDTH, HEIGHT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-max, max, -1, 1, 10, -10);
glRotated(cameraX, 1f, 0f, 0);
glRotated(cameraY, 0f, 1f, 0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
drawSkybox(texId);
glViewport(0, 0, WIDTH, HEIGHT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
...
//render camera and other objects
For cube map textures, the texture coordinates are 3-dimensional and treated as a vector form the center of the cube map.
Since you draw a cube, which is centered around (0, 0, 0), you can use the the vertex coordinates for the texture coordinates, too. You do not use a shader program, so you have to use fixed function attributes. Specify the vertex coordinates by glVertexPointer and the texture coordinates by glTexCoordPointer. Enable the client-side capability (glEnableClientState) GL_VERTEX_ARRAY and GL_TEXTURE_COORD_ARRAY.
Specify the Vertex Array Object. It is sufficient to execute that code once at intialization:
glGenBuffers(vbo);
glBindBuffer (GL_ARRAY_BUFFER, vbo[0]);
glBufferData(GL_ARRAY_BUFFER, POINTS, GL_STATIC_DRAW);
glBindBuffer (GL_ARRAY_BUFFER, 0);
glGenVertexArrays(vao);
glBindVertexArray(vao[0]);
glBindBuffer (GL_ARRAY_BUFFER, vbo[0]);
glVertexPointer(3, GL_FLOAT, false, 3 * Float.BYTES, NULL);
glTexCoordPointer (3, GL_FLOAT, false, 3 * Float.BYTES, NULL);
glBindBuffer (GL_ARRAY_BUFFER, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindVertexArray(0);
When you draw the skybox it is sufficient to bind the cubemap texture to enable cube-mapped texturing and to bind the VAO:
private void drawSkybox(){
GL11.glColor4f(1,1,1,1);
glDepthMask(false);
glEnable(GL_TEXTURE_CUBE_MAP);
glBindTexture(GL_TEXTURE_CUBE_MAP, texID);
glBindVertexArray(vao[0]);
glDrawArrays(GL_TRIANGLES, 0, 36);
glBindVertexArray(0);
glDepthMask(true);
glDisable(GL_TEXTURE_CUBE_MAP);
}
There are some further issues:
The image is not read correctly. See I have a black texture.
Clear the depth buffer after drawing the skybox. See Skybox textures do not display correctly
I'm new to OpenGL, and I am trying to load a .obj file into my Android application and display it using OpenGLES 2. The object is rendered. But there are some spaces in it like the below image. How can I fix this?
This is the actual object.
Here is my code (additional: I'm using this in MaxST Instant tracker)
objLoader = new ObjLoader(context, "andy.obj");
numFaces = objLoader.numFaces;
positions = ByteBuffer.allocateDirect(objLoader.positions.length * mBytesPerFloat)
.order(ByteOrder.nativeOrder()).asFloatBuffer();
positions.put(objLoader.positions).position(0);
normals = ByteBuffer.allocateDirect(objLoader.normals.length * mBytesPerFloat)
.order(ByteOrder.nativeOrder()).asFloatBuffer();
normals.put(objLoader.normals).position(0);
textureCoordinates = ByteBuffer.allocateDirect(objLoader.textureCoordinates.length * mBytesPerFloat)
.order(ByteOrder.nativeOrder()).asFloatBuffer();
textureCoordinates.put(objLoader.textureCoordinates).position(0);
ByteBuffer bb = ByteBuffer.allocateDirect(objLoader.positions.length * Float.SIZE / 8);
bb.order(ByteOrder.nativeOrder());
vertexBuffer = bb.asFloatBuffer();
vertexBuffer.put(positions);
vertexBuffer.position(0);
bb = ByteBuffer.allocateDirect(objLoader.textureCoordinates.length * Float.SIZE / 8);
bb.order(ByteOrder.nativeOrder());
textureCoordBuff = bb.asFloatBuffer();
textureCoordBuff.put(textureCoordinates);
textureCoordBuff.position(0);
shaderProgramId = ShaderUtil.createProgram(VERTEX_SHADER_SRC, FRAGMENT_SHADER_SRC);
positionHandle = GLES20.glGetAttribLocation(shaderProgramId, "a_position");
textureCoordHandle = GLES20.glGetAttribLocation(shaderProgramId, "a_texCoord");
mvpMatrixHandle = GLES20.glGetUniformLocation(shaderProgramId, "u_mvpMatrix");
textureHandle = GLES20.glGetUniformLocation(shaderProgramId, "u_texture");
textureNames = new int[1];
GLES20.glGenTextures(1, textureNames, 0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureNames[0]);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
(ObjLoader class is from here)
Here is my draw method
#Override
public void draw() {
GLES20.glUseProgram(shaderProgramId);
GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false,
0, vertexBuffer);
GLES20.glEnableVertexAttribArray(positionHandle);
GLES20.glVertexAttribPointer(textureCoordHandle, 2, GLES20.GL_FLOAT, false,
0, textureCoordBuff);
GLES20.glEnableVertexAttribArray(textureCoordHandle);
Matrix.setIdentityM(modelMatrix, 0);
Matrix.multiplyMM(modelMatrix, 0, translation, 0, rotation, 0);
Matrix.multiplyMM(modelMatrix, 0, modelMatrix, 0, scale, 0);
Matrix.multiplyMM(modelMatrix, 0, transform, 0, modelMatrix, 0);
Matrix.multiplyMM(localMvpMatrix, 0, projectionMatrix, 0, modelMatrix, 0);
GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false, localMvpMatrix, 0);
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glUniform1i(textureHandle, 0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureNames[0]);
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, objLoader.positions.length / 3);
GLES20.glDisableVertexAttribArray(positionHandle);
GLES20.glDisableVertexAttribArray(textureCoordHandle);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
}
The model file seems to consist of quads. If the faces are quads, the you have to generate 2 triangles for each face.
Adapt the object loader. e.g.:
class ObjLoader {
// [...]
public ObjLoader(Context context, String file) {
// [...]
switch (parts[0]) {
// [...]
case "f":
// faces: vertex/texture/normal
if (parts.length == 5) {
// triangle 1
faces.add(parts[1]);
faces.add(parts[2]);
faces.add(parts[3]);
// triangle 2
faces.add(parts[1]);
faces.add(parts[3]);
faces.add(parts[4]);
}
else {
faces.add(parts[1]);
faces.add(parts[2]);
faces.add(parts[3]);
}
break;
}
// [...]
}
}
So, I'm working on a game with OpenGL and Java, and I've decided to use JSFML for my windowing, text, image loading, etc... And, i'm having some small issues.
The OpenGL drawing works fine until I try to play with depth then it just doesn't work!
Here's my code so far:
import java.io.*;
import org.jsfml.graphics.*;
import org.jsfml.window.*;
import static org.lwjgl.opengl.GL11.*;
//import static org.lwjgl.util.glu.GLU.*;
public class Main
{
static Image icon;
static Texture playert;
static long a, b, c, d;
static float e;
public static void main(String[] args) throws Exception
{
c = 0l;
icon = new Image();
icon.loadFromStream(new FileInputStream("Icon.png"));
ContextSettings contextSettings;
contextSettings = new ContextSettings (24, 8, 0, 2, 1);
VideoMode v = new VideoMode(800, 600);
RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML Game", org.jsfml.window.WindowStyle.DEFAULT, contextSettings);
window.setIcon(icon);
window.setFramerateLimit(120);
Context.getContext().setActive(true);
Text pauseMessage = new Text();
Font font = new Font();
font.loadFromStream(new FileInputStream("Minecraftia.ttf"));
pauseMessage.setFont(font);
pauseMessage.setCharacterSize(20);
pauseMessage.setPosition(0.f, 0.f);
pauseMessage.setColor(new Color(250, 250, 250));
pauseMessage.setString("This is Mission:Iinfinity, prototyped in JSFML");
Text fps = new Text();
fps.setFont(font);
fps.setCharacterSize(20);
fps.setPosition(0.f, 20.f);
fps.setColor(new Color(250, 250, 250));
fps.setString("FPS: " + c);
org.lwjgl.opengl.GLContext.useContext(Context.getContext());
glDepthMask(true);
glClearDepth(1.f);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
float ratio = window.getSize().x / window.getSize().y;
glFrustum(-ratio, ratio, -1.f, 1.f, 1.f, 500.f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
a = System.currentTimeMillis();
d = System.currentTimeMillis();
while (true)
{
window.clear();
if(b - a >= 1000)
{
a = b;
fps.setString("FPS: " + c);
c = 0;
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
window.pushGLStates();
window.draw(pauseMessage);
window.draw(fps);
window.popGLStates();
glPushMatrix();
glTranslatef(0.0f, 0.0f, -10f);
//glRotatef(10f, 0.f, 0.f, 1.f);
glBegin(GL_POLYGON);
glVertex3f(-0.5f, -0.5f, 0);
glVertex3f(-0.5f, 0.5f, 0);
glVertex3f(0.5f, 0.5f, 0);
glVertex3f(0.5f, -0.5f, 0);
glEnd();
glPopMatrix();
window.display();
if(Keyboard.isKeyPressed(Keyboard.Key.ESCAPE))
{
window.close();
System.exit(0);
}
b = System.currentTimeMillis();
c++;
}
}
}
EDIT: Ok, fixed the ContextSettings but that cube still stubbornly refuses to draw further than 1 coord deep or 1 coord back
Of course it is not working, you are constructing the ContextSettings class object this way:
contextSettings = new ContextSettings(0, 4, 2, 32, 32);
The meaning of each parameter in the constructor is, in order:
int depthBits
int stencilBits
int antialiasingLevel
int majorVersion
int minorVersion
You are requesting a render-context that has a 0-bit depth buffer, 4-bit stencil buffer, 2x MSAA, and OpenGL 32.32!
Consider something a little bit more sane like this:
contextSettings = new ContextSettings (24, 8, 0, 2, 1);
24-bit Depth, 8-Bit Stencil, 0x MSAA, OpenGL 2.1.
I am very new in openGL and I use LWJGL.
I do not know how to see if "Mipmaps are working"
This is how I load a Image (64x64) :
private int loadPNGTexture(String filename) {
ByteBuffer buf = null;
int tWidth = 0;
int tHeight = 0;
try {
InputStream in = new FileInputStream(ClassLoader.getSystemResource(filename).getPath());
decoder = new PNGDecoder(in);
tWidth = decoder.getWidth();
tHeight = decoder.getHeight();
buf = BufferUtils.createByteBuffer(4 * decoder.getWidth() * decoder.getHeight());
decoder.decode(buf, decoder.getWidth() * 4, PNGDecoder.Format.RGBA);
buf.flip();
in.close();
} catch (IOException e) {
e.printStackTrace();
System.exit(-1);
}
int texId = GL11.glGenTextures();
GL13.glActiveTexture(GL13.GL_TEXTURE0);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);
GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, tWidth, tHeight, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buf);
GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
return texId;
}
And this is how I draw my Image :
public void drawGL() {
GL11.glPushMatrix();
GL11.glBindTexture(GL11.GL_TEXTURE_2D, playerTextures[0]);
GL11.glBegin(GL11.GL_TRIANGLE_STRIP);
GL11.glTexCoord2f(1, 0);
GL11.glVertex2f(decoder.getWidth(), 0);
GL11.glTexCoord2f(1, 1);
GL11.glVertex2f(decoder.getWidth(), decoder.getWidth());
GL11.glTexCoord2f(0, 0);
GL11.glVertex2f(0, 0);
GL11.glTexCoord2f(0, 1);
GL11.glVertex2f(0, decoder.getWidth());
GL11.glEnd();
GL11.glPopMatrix();
}
The draw is correct, I can see my Image but if I change the DisplayMode (from 800x600 to 1280x960), the Image is not growing up. So the problem is that I need the Image grow up to scale with the resolution.
My question is about jogl. I draw image in canvas display. But I draw polygon on image. I draw polygon but polygn is transparan and not colour. Can ı do it?
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glEnable(GL.GL_BLEND);
BufferedImage bufferedImage = null;
int w = 0;
int h = 0;
try {
I get image and its width and height
bufferedImage = ImageIO.read(OpenGLFuncition.class.getResource("kibris.png"));
w = bufferedImage.getWidth();
h = bufferedImage.getHeight();
} catch (IOException ex) {
}
I creat the image area
WritableRaster raster =
Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
w,
h,
4,
null);
I set the color of the image drawing
ComponentColorModel colorModel =
new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
new int[]{8, 8, 8, 8},
true,
false,
ComponentColorModel.OPAQUE,
DataBuffer.TYPE_BYTE);
BufferedImage dukeImg =
new BufferedImage(colorModel,
raster,
false,
null);
graphic
Graphics2D g = dukeImg.createGraphics();
g.drawImage(bufferedImage, null, null);
DataBufferByte dukeBuf =
(DataBufferByte) raster.getDataBuffer();
byte[] dukeRGBA = dukeBuf.getData();
ByteBuffer bb = ByteBuffer.wrap(dukeRGBA);
bb.position(0);
bb.mark();
gl.glBindTexture(GL.GL_TEXTURE_2D, 13);
gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, w, h, 0, GL.GL_RGBA,
GL.GL_UNSIGNED_BYTE, bb);
int left = 0;
int top = 0;
gl.glEnable(GL.GL_TEXTURE_2D);
gl.glBindTexture(GL.GL_TEXTURE_2D, 13);
gl.glBegin(GL.GL_POLYGON);
gl.glTexCoord2d(0, 0);
gl.glVertex2d(left, top);
gl.glTexCoord2d(1, 0);
gl.glVertex2d(left + w, top);
gl.glTexCoord2d(1, 1);
gl.glVertex2d(left + w, top + h);
gl.glTexCoord2d(0, 1);
gl.glVertex2d(left, top + h);
gl.glEnd();
polygon draw
for (int i = 0; coordinateLoc.length - 1 > i; i++) {
gl.glBegin(GL.GL_POLYGON);
gl.glColor3ub(coordinateLoc[i].get(coordinateLoc[i].size() - 1).getColourred(), coordinateLoc[i].get(coordinateLoc[i].size() - 1).getColourgreen(), coordinateLoc[i].get(coordinateLoc[i].size() - 1).getColourblue());
for (CoordinateXY ca : coordinateLoc[i]) {
// System.out.println(ca.getCoordinateX());
gl.glVertex2i(ca.getCoordinateX(), 449 - ca.getCoordinateY());
}
gl.glEnd();
You should call glcolor() otherwise everything will be transparent.
gl.glTexCoord2d(0, 1);
gl.glcolor(red,green,blue,alpha);
gl.glVertex2d(left, top + h)