I'm trying to make a screenshot saver routines. I'm using the code here as a base, so the resulting code is like this:
public void update(float deltaTime) {
if(Gdx.input.isKeyPressed(Keys.ESCAPE)) {
Gdx.app.exit();
}
if(Gdx.input.isKeyPressed(Keys.F10)) {
this.saveScreenshot(new FileHandle(new File("screenshots/screenShot001.png")));
}
}
public void saveScreenshot(FileHandle file) {
Pixmap pixmap = getScreenshot(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
PixmapIO.writePNG(file, pixmap);
pixmap.dispose();
}
public Pixmap getScreenshot(int x, int y, int w, int h, boolean flipY) {
Gdx.gl.glPixelStorei(GL10.GL_PACK_ALIGNMENT, 1);
final Pixmap pixmap = new Pixmap(w, h, Format.RGBA8888);
ByteBuffer pixels = pixmap.getPixels();
Gdx.gl.glReadPixels(x, y, w, h, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, pixels);
final int numBytes = w * h * 4;
byte[] lines = new byte[numBytes];
if (flipY) {
final int numBytesPerLine = w * 4;
for (int i = 0; i < h; i++) {
pixels.position((h - i - 1) * numBytesPerLine);
pixels.get(lines, i * numBytesPerLine, numBytesPerLine);
}
pixels.clear();
pixels.put(lines);
} else {
pixels.clear();
pixels.get(lines);
}
return pixmap;
}
The file is created and it seems to be a correct PNG image with a correct size but it is a blank one. The application is the sample that setup-ui makes, and shows libGDX logo. Any idea of the problem?
Taken from your comment:
#Override public void render() {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
controller.update(Gdx.graphics.getDeltaTime());
batch.setProjectionMatrix(camera.combined);
batch.begin();
sprite.draw(batch);
batch.end();
}
The problem is that you clear the color, then check the input (and make a screenshot) and then render the logo.
Move the controller.update(Gdx.graphics.getDeltaTime()); at the end of your render method, after you rendered the logo (batch.end()).
Related
I am trying to draw an .obj file offscreen under Android.
The image should then be passed to OpenCV for further use as a matrix.
In 2D the whole thing already works without problems.
public class ObjDrawer extends PApplet {
PGraphics buffer;
PShape obj;
int width;
int height;
public ObjDrawer(int width, int height) {
this.width = width;
this.height = height;
setup();
}
#Override
public void setup() {
buffer = createGraphics(this.width, this.height, P3D);
//obj = loadShape("Wuerfel_40mm.obj");
noLoop();
}
public Mat testDraw() {
buffer.beginDraw();
buffer.background(255);
buffer.ellipse(200, 200, 100, 100);
//buffer.shape(obj);
buffer.endDraw();
return toMat(buffer.get());
}
Mat toMat(PImage image) {
//source: https://gist.github.com/Spaxe/3543f0005e9f8f3c4dc5
int w = image.width;
int h = image.height;
Mat mat = new Mat(h, w, CvType.CV_8UC4);
byte[] data8 = new byte[w * h * 4];
int[] data32 = new int[w * h];
arrayCopy(image.pixels, data32);
ByteBuffer bBuf = ByteBuffer.allocate(w * h * 4);
IntBuffer iBuf = bBuf.asIntBuffer();
iBuf.put(data32);
bBuf.get(data8);
mat.put(0, 0, data8);
return mat;
}
}
When using 3D, I now get the following error message:
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean processing.core.PGraphics.isGL()' on a null object reference
at processing.core.PApplet.makeGraphics(PApplet.java:1584)
at processing.core.PApplet.createGraphics(PApplet.java:1568)
at Analyzer.ObjDrawer.setup(ObjDrawer.java:52)
at Analyzer.ObjDrawer.<init>(ObjDrawer.java:45)
at com.quickbirdstudios.opencvexample.MainActivity$cvCameraViewListener$1.onCameraFrame(MainActivity.kt:75)
at org.opencv.android.CameraBridgeViewBase.deliverAndDrawFrame(CameraBridgeViewBase.java:392)
at org.opencv.android.JavaCameraView$CameraWorker.run(JavaCameraView.java:373)
at java.lang.Thread.run(Thread.java:920)
In my research I read about a3d, this is missing for me. Since all the stuff I found regarding a3d was about 10 years old: has anything changed in this regard or has it been replaced or do I need to include this separately?
I have included Processing as in the tutorial on https://android.processing.org/tutorials/android_studio/index.html
integrated. I use Android Mode for Processing 3 4.3.0, because the mode manager in Processing 4 is currently broken.
many thanks in advance!
I have 3 FloatBuffers - vertices, normals and colors which contain what the name suggests. I also have an IntBuffer to keep track of the indexing.
The data looks correct, but I'm having trouble displaying it. I just see a blank canvas. I'm not sure what I am doing wrong. I'm guessing something is being overlooked in init(), display(), reshape() and dispose(). Can anyone tell me if you find something glaringly wrong in the code below, and why you think nothing is being displayed?
#Override
public void init(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
gl.glClearColor(.0f, .0f, .2f, 0.9f);
gl.glEnable(GL2.GL_DEPTH_TEST);
gl.glDepthFunc(GL2.GL_LESS);
gl.glEnable(GL2.GL_CULL_FACE);
gl.glEnable(GL2.GL_LIGHTING);
gl.glEnable(GL2.GL_LIGHT0);
gl.glEnable(GL2.GL_AUTO_NORMAL);
gl.glEnable(GL2.GL_NORMALIZE);
gl.glFrontFace(GL2.GL_CCW);
gl.glCullFace(GL2.GL_BACK);
gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST);
gl.glShadeModel(GL2.GL_SMOOTH);
if (viewMesh) {
gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_LINE);
} else {
gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_FILL);
}
glu = new GLU();
// Build the VBOs
VBO = IntBuffer.allocate(4);
gl.glGenBuffers(4, VBO);
vertVBOID = VBO.get(0);
normalVBOID = VBO.get(1);
colorVBOID = VBO.get(2);
indexVBOID = VBO.get(3);
// vertices
int vsize = sd.verts.capacity() * BufferUtil.SIZEOF_FLOAT;
gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, vertVBOID); // get a valid name
gl.glBufferData(GL2.GL_ARRAY_BUFFER, vsize, sd.verts, GL2.GL_STATIC_DRAW);
gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, 0); // reset
// normals
int nsize = sd.normals.capacity() * BufferUtil.SIZEOF_FLOAT;
gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, normalVBOID);
gl.glBufferData(GL2.GL_ARRAY_BUFFER, nsize, sd.normals, GL2.GL_STATIC_DRAW);
gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, 0);
// colors
int csize = sd.colors.capacity() * BufferUtil.SIZEOF_FLOAT;
gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, colorVBOID);
gl.glBufferData(GL2.GL_ARRAY_BUFFER, csize, sd.colors, GL2.GL_STATIC_DRAW);
gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, 0);
int isize = sd.indices.capacity() * BufferUtil.SIZEOF_INT;
gl.glBindBuffer(GL2.GL_ELEMENT_ARRAY_BUFFER, indexVBOID);
gl.glBufferData(GL2.GL_ELEMENT_ARRAY_BUFFER, isize, sd.indices, GL2.GL_STATIC_DRAW);
gl.glBindBuffer(GL2.GL_ELEMENT_ARRAY_BUFFER, 0);
// sd.verts = null; // copy of data is no longer necessary, it is in the graphics card now.
// sd.colors = null;
// sd.normals = null;
// sd.indices = null;
}
#Override
public void display(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
glu.gluLookAt(45, 0, 0, 0, 0, 0, 0.0, 1.0, 0.0);
gl.glScalef(scale, scale, scale);
gl.glRotatef(rot, 0, 1, 0);
gl.glTranslatef(-sd.tr_x, -sd.tr_y, -sd.tr_z);
gl.glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
gl.glEnableClientState(GLPointerFunc.GL_NORMAL_ARRAY);
gl.glEnableClientState(GLPointerFunc.GL_COLOR_ARRAY);
gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, normalVBOID);
gl.glNormalPointer(GL2.GL_FLOAT, 0, 0);
gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, colorVBOID);
gl.glColorPointer(3, GL2.GL_FLOAT, 0, 0);
gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, vertVBOID);
gl.glVertexPointer(3, GL2.GL_FLOAT, 0, 0);
gl.glBindBuffer(GL2.GL_ELEMENT_ARRAY_BUFFER, indexVBOID);
gl.glDrawElements(GL2.GL_TRIANGLES, sd.indices.capacity(), GL2.GL_INT, 0);
gl.glBindBuffer(GL2.GL_ELEMENT_ARRAY_BUFFER, 0); // unbind it
gl.glDisableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
gl.glDisableClientState(GLPointerFunc.GL_NORMAL_ARRAY);
gl.glDisableClientState(GLPointerFunc.GL_COLOR_ARRAY);
}
#Override
public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
GL2 gl = drawable.getGL().getGL2();
double fov = (Math.PI / 4.0);
double zmm = Math.abs(sd.min_z - sd.max_z);
camdist = (zmm / 2.0) / Math.tan(fov / 2.0);
h = (h == 0) ? 1 : h;
gl.glViewport(0, 0, w, h);
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(camdist, w / (float) h, 0.1f, 1000.0);
}
/**
* Initilaize graphics
*/
public void initOGL() {
profile = GLProfile.get(GLProfile.GL2);
caps = new GLCapabilities(profile);
caps.setHardwareAccelerated(true);
canvas = new GLCanvas(caps);
canvas.addGLEventListener(this);
canvas.requestFocusInWindow();
getContentPane().add(canvas); // add to the frame
}
#Override
public void dispose(GLAutoDrawable drawable) {
}
One clear problem is in the draw call:
gl.glDrawElements(GL2.GL_TRIANGLES, sd.indices.capacity(), GL2.GL_INT, 0);
GL_INT is not valid for the type argument of glDrawElements(). The only valid values are GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT and GL_UNSIGNED_INT. So the call needs to be:
gl.glDrawElements(GL2.GL_TRIANGLES, sd.indices.capacity(), GL2.GL_UNSIGNED_INT, 0);
Anytime you have a problem with OpenGL code not working as expected, make sure that you call glGetError(). With the call from your code, you should immediately get a GL_INVALID_ENUM error.
Also, your perspective setup code looks somewhat suspicious. I don't fully understand what you're trying to do there, but even just the naming suggests a possible misunderstanding:
glu.gluPerspective(camdist, w / (float) h, 0.1f, 1000.0);
The first argument of gluPerspective() is the field-of-view angle (in degrees), not a distance.
I imported:
import javax.swing.ImageIcon;
and I used this code to import the PNG file. (i know i can create a black square easily, but it is the importing any image to my game that i want).
Image player1 = Toolkit.getDefaultToolkit().createImage("Users/Documents/JavaGameImages/Tag/BlackSquare.png");
I tried to call this image later down, but the image did not appear in the window. (assume myX = 100 and myY = 100)
public void paint(Graphics g) {
g.setColor(BackgroundColor);
g.fillRect(WindowWidth, WindowHeight, 1000, 1000);
/////////////////////// The code below is where i am having trouble:
g.drawImage(player1, myX, myY, null);
When you are building that code for distribution, you'll probably want to put the image into the jar file with the class files. What I do is put it into the same directory as the class that's accessing it, and then I access it with getClass().getResource(fileName), as in this snippet of code from a textured background border:
final Toolkit toolKit = Toolkit.getDefaultToolkit();
URL imgURL = getClass().getResource(textureFileName);
if (imgURL != null)
{
Image tmpImage = toolKit.createImage(imgURL);
toolKit.prepareImage(tmpImage, -1, -1,
new ImageObserver() {
public boolean imageUpdate(Image updatedImage, int infoFlags, int x,
int y, int width, int height)
{
if ((infoFlags & ImageObserver.ALLBITS) == ImageObserver.ALLBITS)
{
int w = updatedImage.getWidth(null);
int h = updatedImage.getHeight(null);
BufferedImage backgroundImage = new BufferedImage(w, h,
BufferedImage.TYPE_INT_ARGB_PRE);
Graphics2D g = backgroundImage.createGraphics();
g.drawImage(updatedImage, 0, 0, null);
g.dispose();
Rectangle rect = new Rectangle(0, 0, w, h);
texture = new TexturePaint(backgroundImage, rect);
return false;
}
return true;
}
});
}
I'm having a problem with a simple 2d tile-based engine I'm working on. On my home computer (Windows 7 64bit, jogl 1.1.1) the textures bind properly to the tiles but on my laptop (Windows Vidta 32bit, jogl 1.1.1) they appear broken.
The sprites image is 600x100 (each sprite being 100x100).
Here is the textureManager class that I'm using.
public class TextureManager {
private static Texture textureAtlas;
private static Map<String, TextureCoords> locations;
private static String imageName;
public TextureManager() {
locations = new HashMap<String, TextureCoords>();
}
public static void loadAtlas(String name) {
if(textureAtlas != null) {
if(imageName == name) return;
textureAtlas.dispose();
}
imageName = name;
try {
textureAtlas = TextureIO.newTexture(new File("textures/" + name + ".png"), true);
}
catch (GLException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
setAtlasLocations();
}
private static void setAtlasLocations() {
locations.put("blank", textureAtlas.getSubImageTexCoords(0, 0, 100, 100));
locations.put("tree1", textureAtlas.getSubImageTexCoords(100, 0, 200, 100));
locations.put("tree2", textureAtlas.getSubImageTexCoords(200, 0, 300, 100));
locations.put("tree3", textureAtlas.getSubImageTexCoords(300, 0, 400, 100));
locations.put("rock", textureAtlas.getSubImageTexCoords(400, 0, 500, 100));
}
public static void bindTexture() {
textureAtlas.bind();
}
public static TextureCoords getCoords(String name) {
return locations.get(name);
}
}
This is the rendering code:
public void draw(GL gl) {
gl.glEnable(GL.GL_TEXTURE_2D);
TextureManager.bindTexture();
int width = map.width();
int height = map.height();
float x = InterfaceManager.mapX;
float y = InterfaceManager.mapY;
gl.glTranslatef(x, y - height, 0);
gl.glBegin(GL.GL_QUADS);
gl.glNormal3f(0.0f, 0.0f, 1.0f);
gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
for(int w = 0; w < width; w++) {
for(int h = 0; h < height; h++) {
TextureCoords coords = getCoord(map.getTileType(w, h));
gl.glTexCoord2f(coords.left(), coords.bottom());
gl.glVertex3i(w, h, 0);
gl.glTexCoord2f(coords.right(), coords.bottom());
gl.glVertex3i(w+1, h, 0);
gl.glTexCoord2f(coords.right(), coords.top());
gl.glVertex3i(w+1, h+1, 0);
gl.glTexCoord2f(coords.left(), coords.top());
gl.glVertex3i(w, h+1, 0);
}
}
gl.glEnd();
gl.glTranslatef(-x, -y + height, 0);
gl.glDisable(GL.GL_TEXTURE_2D);
}
private TextureCoords getCoord(int tileType) {
if(tileType == 0) return TextureManager.getCoords("blank");
else if(tileType == 1) return TextureManager.getCoords("rock");
else if(tileType == 2) return TextureManager.getCoords("tree1");
else if(tileType == 3) return TextureManager.getCoords("tree2");
else if(tileType == 4) return TextureManager.getCoords("tree3");
else return TextureManager.getCoords("blank");
}
I know opengl is supposed to be platform independent, and since I'm using the same versions of opengl on both, I'm assuming there's probably a bug in my code.
Hopefully someone more experienced with it can help me out with this problem. Thanks!
EDIT: Here is a picture of the skewed result.
The trees along the top and right side is actually supposed to be the rock in the sprite below.
This is the sprite file:
The automatically generated mipmaps by OpenGL were causing the problem. Changing the below line to not allow auto mipmapping fixes the problem.
textureAtlas = TextureIO.newTexture(new File("textures/" + name + ".png"), false);
If anyone would like to comment on how i should create my sprite file to allow auto mipmapping, or if this should even be on, please do :)
With mipmapping off, as i move the character around, some tiles get a black line beneath them. I'll have to figure out how to make the sprite image mipmap-able.
EDIT: Make the file square and to the power of 2.
Situation:
I use Vertex Buffer Objects in OpenGL (LWJGL java binding, GL11) to render rectangles. I can render textures (vertices and texture coordinates) without any problems, also adding color to it leads to the desired effect (like making it semi-translucent). Only using vertices and color makes it invisible.
Researchs:
Disabling alpha test and blending leads to a black rect, which is obviously the vertex and color VBO without alpha testing and blending -> It is rendered.
Disabling only alpha testing leads to the same result like before.
Disabling only blending does also not help.
I can't find any error in my code, neither I can find the source of the problem.
States activated when rendering:
GL_TEXTURE_2D, GL_SMOOTH (Shade Model), GL_DEPTH_TEST, GL_LEQUAL (Depth Func), GL_BACK (Cull Face)
Blend Func: GL_SRC_ALPHA and GL_ONE_MINUS_SRC_ALPHA
Alpha Func: GL_GREATER and 0.1F
Projection: glOrtho(0, 1, 1, 0, 0, 1000);
All rectangles are on the Z axis at -1 (I called once glTranslatef(0,0,-1) before rendering the GUI), on the X and Y axis between 0 and 1. Additionally I have to say that a texture is bound, but this should not be the problem.
Important Code
Note: The Color class basically wraps an RGBA color and has been written by me, so it is not the Color class of the java.awt package.
Note 2: I know that my VertexBufferObject class is not optimized with dynamic draw VBOs, but I could not find time to handle that.
Vertex Buffer Object
private boolean isStatic;
private boolean hasColor;
private boolean hasTexture;
private boolean hasNormals;
private int renderMode;
private int vertices;
private int vertexSize;
private ByteBuffer buffer;
private int vboId;
private boolean isDirty;
public VertexBufferObject (int renderMode, boolean isStatic, boolean hasColor, boolean hasTexture, boolean hasNormals, int vertices) {
this.isStatic = isStatic;
this.hasColor = hasColor;
this.hasTexture = hasTexture;
this.hasNormals = hasNormals;
this.vertices = vertices;
this.renderMode = renderMode;
vertexSize = calculateVertexSize();
}
public void markDirty () {
isDirty = true;
}
public void createBuffer () {
buffer = BufferUtils.createByteBuffer(getVertexSize());
markDirty();
}
public void createVBO () {
buffer.flip();
vboId = ARBVertexBufferObject.glGenBuffersARB();
// Buffer into vbo
ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, vboId);
ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, buffer, (isStatic ? ARBVertexBufferObject.GL_STATIC_DRAW_ARB : ARBVertexBufferObject.GL_DYNAMIC_DRAW_ARB));
// Unbind
ARBVertexBufferObject.glUnmapBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB);
ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, 0);
if (isStatic) buffer = null;
}
public void addVertex (float x, float y, float z) {
buffer.putFloat(x);
buffer.putFloat(y);
buffer.putFloat(z);
}
public void addTextureCoordinates (float u, float v) {
buffer.putFloat(u);
buffer.putFloat(v);
}
public void addColor (Color color) {
addColor(color.getRGBAInt());
}
public void addColor (int rgba) {
buffer.putInt(rgba);
System.out.println(Integer.toBinaryString(rgba));
}
public void addNormal (byte x, byte y, byte z) {
buffer.put(x);
buffer.put(y);
buffer.put(z);
}
public void setVertex (int index, float x, float y, float z) {
index *= vertexSize;
buffer.position(index);
buffer.putFloat(x);
buffer.putFloat(y);
buffer.putFloat(z);
markDirty();
}
public void setTextureCoordinates (int index, float u, float v) {
index *= vertexSize + 12;
buffer.position(index);
buffer.putFloat(u);
buffer.putFloat(v);
markDirty();
}
public void setColor (int index, Color color) {
setColor(index, color.getRGBAInt());
}
public void setColor (int index, int rgba) {
index *= vertexSize + (hasTexture ? 20 : 12);
buffer.position(index);
buffer.putInt(rgba);
markDirty();
}
public void setNormal (int index, byte x, byte y, byte z) {
index *= vertexSize - 3;
buffer.position(index);
buffer.put(x);
buffer.put(y);
buffer.put(z);
markDirty();
}
public void draw () {
draw(0, vertices);
}
public void draw (int start, int vertexNumber) {
if (vboId == 0) return;
ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, vboId);
// Update Dynamic VBO
if (isDirty && !isStatic) {
buffer.position(0);
int vboType = isStatic ? ARBVertexBufferObject.GL_STATIC_DRAW_ARB : ARBVertexBufferObject.GL_DYNAMIC_DRAW_ARB;
ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, 0, vboType);
ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, buffer, vboType);
isDirty = false;
}
// Stride
int stride = 12;
if (hasTexture) stride += 8;
if (hasColor) stride += 4;
if (hasNormals) stride += 3;
// Apply Pointers
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
GL11.glVertexPointer(3, GL11.GL_FLOAT, stride, 0);
if (hasTexture) {
GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
GL11.glTexCoordPointer(2, GL11.GL_FLOAT, stride, 12);
}
if (hasColor) {
GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
GL11.glColorPointer(4, GL11.GL_UNSIGNED_BYTE, stride, hasTexture ? 20 : 12);
}
if (hasNormals) {
GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);
GL11.glNormalPointer(GL11.GL_BYTE, stride, stride - 3);
}
// Draw with specified render mode
GL11.glDrawArrays(renderMode, start, vertexNumber);
// Unbind VBO
if (hasTexture) GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
if (hasColor) GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);
if (hasNormals) GL11.glDisableClientState(GL11.GL_NORMAL_ARRAY);
GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, 0);
}
public void destroy () {
ARBVertexBufferObject.glDeleteBuffersARB(vboId);
}
private int calculateVertexSize () {
return vertices * 12 + vertices * (hasTexture ? 8 : 0) + vertices * (hasColor ? 4 : 0) + vertices * (hasNormals ? 4 : 0);
}
ColorFrameRenderer (The Rectangle, basically)
private VertexBufferObject vbo;
private Color color;
public ColorFrameRenderer(int sizeX, int sizeY, Color color) {
super(sizeX, sizeY);
this.color = color;
}
#Override
public void render() {
if (!render) return;
vbo.draw();
}
#Override
public void init() {
vbo = new VertexBufferObject(GL11.GL_QUADS, false, true, false, false, 4);
vbo.createBuffer();
vbo.addVertex(x, y, 0);
vbo.addColor(color);
vbo.addVertex(x, y + sizeY, 0);
vbo.addColor(color);
vbo.addVertex(x + sizeX, y + sizeY, 0);
vbo.addColor(color);
vbo.addVertex(x + sizeX, y, 0);
vbo.addColor(color);
vbo.createVBO();
}
#Override
public void setPosition (float x, float y, float z) {
super.setPosition(x, y, z);
if (vbo != null) {
vbo.setVertex(0, this.x, this.y, 0);
vbo.setVertex(1, this.x, this.y + sizeY, 0);
vbo.setVertex(2, this.x + sizeX, this.y + sizeY, 0);
vbo.setVertex(3, this.x + sizeX, this.y, 0);
}
}
Thanks for any help and advice!
Please understand that I can not provide the whole code due to a more or less secret project it belongs to.
States activated when rendering:
GL_TEXTURE_2D
I think that's your problem there: If you don't want to texture, disable GL_TEXTURE_…. Otherwise the whole primitive will sample from the last used texture coordinates, possibly a alpha=0 sample.