Sign in to follow this  
LizardCPP

OpenGL VBO and interleaved data problem with JOGL

Recommended Posts

LizardCPP    206
It's been a while since I have done any OpenGL coding and now I'm trying to get back into the game using JOGL, OpenGL bindings for Java. I got a simple program up and running that draws two triangles as a quad using the old fixed-function pipeline (i.e. glBegin(GL_TRIANGLES) / glEnd()). Now I'm trying to get it to work with VBO:s, indexed interleaved vertex data as i used to do it 5 years ago. Then after that I'm thinking of working my way up to use the 3.2 profile.

Update: I created a simpler test program that displays my problem in one file, see post 6 in this thread.

Update 2: This has now been solved, see post 7.

The sample program requests a OpenGL 2.0 profile and then tries to render two triangles as a quad with one color per vertex. The vertex data is interleaved with first 3 floats for position and then 4 floats for color. 4 vertex is set in a VBO and then 6 indices are set in a index buffer. Result is a black window, nothing is rendered,glGetError returns 0 if called after glDrawRangeElements().

Geometry class:

import java.nio.Buffer;

public class Geometry
{
/**
*
*/

private VertexFormat vertexFormat;

/**
*
*/

private Buffer vertexBuffer;

/**
*
*/

private Buffer indexBuffer;


/**
* @param vertexFormat
* @param vertexBuffer
* @param indexBuffer
*/

public Geometry(VertexFormat vertexFormat, Buffer vertexBuffer, Buffer indexBuffer)
{
this.vertexFormat = vertexFormat;
this.vertexBuffer = vertexBuffer;
this.indexBuffer = indexBuffer;
}


/**
* @return
*/

public int getStride()
{
return vertexFormat.getStride();
}


public Buffer getVertexData()
{
return vertexBuffer;
}

public Buffer getIndexData()
{
return indexBuffer;
}
}











JOGLBufferObject class:

import javax.media.opengl.GL2;
import javax.media.opengl.GLContext;
import java.nio.Buffer;

class JOGLBufferObject implements BufferObject
{
/**
* The OpenGL api object
*/

private GL2 gl;

/**
* This will either be set to GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER
*/

private int type;

/**
* Size of the buffer in bytes
*/

private int size;

/**
* The buffers id
*/

private int[] bufferId;


/**
*
* @param type the type of the buffer, will either be GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER
* @param size size of the buffer in bytes
*/

private JOGLBufferObject(int type, int size)
{
this.gl = GLContext.getCurrentGL().getGL2();

this.type = type;
this.bufferId = new int[1];
this.size = size;

gl.glGenBuffers(1, bufferId, 0);
gl.glBindBuffer(type, bufferId[0]);
gl.glBufferData(type, size, null, GL2.GL_DYNAMIC_DRAW);
}


/**
*
* @param size
* @return
*/

public static JOGLBufferObject createVertexBuffer(int size)
{
return new JOGLBufferObject(GL2.GL_ARRAY_BUFFER, size);
}


/**
*
* @param size
* @return
*/

public static JOGLBufferObject createIndexBuffer(int size)
{
return new JOGLBufferObject(GL2.GL_ELEMENT_ARRAY_BUFFER, size);
}


/**
* Retrieve the size of the buffer
*
* @return size of the buffer
*/

public int getSize()
{
return size;
}


/**
*
*/

public void destroy()
{
gl.glDeleteBuffers(1, bufferId, 0);
}


/**
*
*/

public void bind()
{
gl.glBindBuffer(type, bufferId[0]);
}


/**
*
*/

public void unbind()
{
gl.glBindBuffer(type, 0);
}


/**
*
* @param offset
* @param size
* @param buffer
*/

public void update(int offset, int size, Buffer buffer)
{
gl.glBufferSubData(type, offset, size, buffer);
}
}











Setup of geometry:

float[] vertexData = new float[]
{
0.75f, 0.25f, -2.0f, 1.0f, 0.0f, 0.0f, 1.0f,
0.75f, 0.75f, -2.0f, 0.0f, 1.0f, 0.0f, 1.0f,
0.25f, 0.25f, -2.0f, 0.0f, 0.0f, 1.0f, 1.0f,
0.25f, 0.75f, -2.0f, 0.5f, 0.5f, 0.5f, 1.0f
};


ByteBuffer vertexByteBuffer = ByteBuffer.allocateDirect(7 * 4 * 4);
FloatBuffer vertexBuffer = vertexByteBuffer.asFloatBuffer();
vertexBuffer.put(vertexData);

int[] indexData = new int[]
{
0, 1, 2, 2, 1, 3
};

ByteBuffer indexByteBuffer = ByteBuffer.allocateDirect(6 * 4);
IntBuffer indexBuffer = indexByteBuffer.asIntBuffer();
indexBuffer.put(indexData);

VertexFormat vertexFormat = new VertexFormat(7 * 4);
geometry = new Geometry(vertexFormat, vertexByteBuffer, indexByteBuffer);










JOGLRenderer, it's the render(Geometry geometry) function that draws nothing:

import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GLContext;
import javax.media.opengl.glu.GLU;
import java.nio.Buffer;

public class JOGLRenderer implements Renderer
{
/**
*
*/

private GL2 gl;

/**
*
*/

private GLU glu;

/**
*
*/

private BufferObject vertexBuffer;

/**
*
*/

private BufferObject indexBuffer;

// TEMP
private boolean setupDone = false;


/**
*/

public JOGLRenderer()
{
this.gl = GLContext.getCurrentGL().getGL2();
this.glu = new GLU();

this.vertexBuffer = JOGLBufferObject.createVertexBuffer(1024);
this.indexBuffer = JOGLBufferObject.createIndexBuffer(1024);

gl.glShadeModel(GL2.GL_SMOOTH);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glClearDepth(1.0f);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(GL.GL_LEQUAL);
gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
}


@Override
public void reshape(int x, int y, int width, int height)
{
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();

gl.glViewport(0, 0, width, height);

gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45.0f, (float) width / (float) height, 0.1f, 100.0f);

gl.glMatrixMode(GL2.GL_MODELVIEW);
}

@Override
public void prepare()
{
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
}

@Override
public void render(OLDGeometry oldGeometry)
{
gl.glBegin(GL.GL_TRIANGLES);

gl.glColor3f(oldGeometry.color.getX(), oldGeometry.color.getY(), oldGeometry.color.getZ());

gl.glVertex3f(oldGeometry.topLeft.getX(), oldGeometry.topLeft.getY(), oldGeometry.topLeft.getZ());
gl.glVertex3f(oldGeometry.topRight.getX(), oldGeometry.topRight.getY(), oldGeometry.topRight.getZ());
gl.glVertex3f(oldGeometry.bottomLeft.getX(), oldGeometry.bottomLeft.getY(), oldGeometry.bottomLeft.getZ());

gl.glVertex3f(oldGeometry.bottomLeft.getX(), oldGeometry.bottomLeft.getY(), oldGeometry.bottomLeft.getZ());
gl.glVertex3f(oldGeometry.topRight.getX(), oldGeometry.topRight.getY(), oldGeometry.topRight.getZ());
gl.glVertex3f(oldGeometry.bottomRight.getX(), oldGeometry.bottomRight.getY(), oldGeometry.bottomRight.getZ());

gl.glEnd();
}

@Override
public void render(Geometry geometry)
{
Buffer vertexBufferData = geometry.getVertexData();
Buffer indexBufferData = geometry.getIndexData();
int stride = geometry.getStride(); // the stride is here 28 i.e. 7*4


gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL2.GL_COLOR_ARRAY);


if (!setupDone)
{
vertexBuffer.bind();
indexBuffer.bind();

vertexBuffer.update(0, vertexBufferData.capacity(), vertexBufferData); // capacity returns 112 i.e. 7*4*4
indexBuffer.update(0, indexBufferData.capacity(), indexBufferData); // capacity returns 24 i.e. 6*4

setupDone = true;
}


gl.glVertexPointer(3, GL2.GL_FLOAT, stride, 0);
gl.glColorPointer(4, GL2.GL_FLOAT, stride, 3 * 4);


gl.glDrawRangeElements(GL2.GL_TRIANGLES, 0, 5, 2, GL2.GL_UNSIGNED_INT, 0);

gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL2.GL_COLOR_ARRAY);
}

@Override
public void present()
{
// No need to swap buffers, jogl does that for me
}
}











Render loop:

renderer.prepare();
renderer.render(geometry);
renderer.present();












Can anyone see what I'm doing wrong?

[Edited by - LizardCPP on November 13, 2010 8:00:52 AM]

Share this post


Link to post
Share on other sites
karwosts    840

gl.glDrawRangeElements(GL2.GL_TRIANGLES, 0, 5, 2, GL2.GL_UNSIGNED_INT, 0);



I think you've got the wrong value for 'count' here. It should be the number of indices, not the number of primitives. I believe this code only draws two vertices and quits, so you're not completing the first triangle.

Share this post


Link to post
Share on other sites
LizardCPP    206
Quote:
Original post by karwosts
*** Source Snippet Removed ***

I think you've got the wrong value for 'count' here. It should be the number of indices, not the number of primitives. I believe this code only draws two vertices and quits, so you're not completing the first triangle.



Thanks for your replay, but I have now tried a count between 2-6 nothing is rendered in any case.


Share this post


Link to post
Share on other sites
karwosts    840
I realize this is a bit of work for you, but can you redo your code into a nice little linear flow without so many function calls? I found myself rolling up and down the screen about 50 times trying to follow the flow of your program and it's difficult to gather in my head in what order things are happening.

maybe just make a new quickie render hack function that is like the following:


glGenBuffers()
glBindBuffer()
glBufferData()
glBindBuffer()
glBufferData()
glVertexPointer()
glColorPointer()
glDrawElements()



It doesn't have to be clean and you can break on the second frame so you don't have to worry about initializing outside of your render loop, but that's probably the best way to get the basics nailed down, and once you have it working, you can OO'ize your code into classes. But just for me trying to read it's very difficult to follow.

You can certainly choose not to do this, but it's much easier to debug that way.

Share this post


Link to post
Share on other sites
LizardCPP    206
Quote:
Original post by karwosts
I realize this is a bit of work for you, but can you redo your code into a nice little linear flow without so many function calls? I found myself rolling up and down the screen about 50 times trying to follow the flow of your program and it's difficult to gather in my head in what order things are happening.

maybe just make a new quickie render hack function that is like the following:

*** Source Snippet Removed ***

It doesn't have to be clean and you can break on the second frame so you don't have to worry about initializing outside of your render loop, but that's probably the best way to get the basics nailed down, and once you have it working, you can OO'ize your code into classes. But just for me trying to read it's very difficult to follow.

You can certainly choose not to do this, but it's much easier to debug that way.


Yeah, I'll think I have to do that. Create a single class that does this without the OO. I'll get back to this post tomorrow if I can't get that to work.

Thanks for trying to help me.

Share this post


Link to post
Share on other sites
LizardCPP    206
Ok I have created a single file that displays my problem, it can be compiled and run if one has a java SDK and JOGL.

The problem is still that nothing is rendered. glGetError returns 0 after glDrawRangelElements.


import com.jogamp.opengl.util.AnimatorBase;
import com.jogamp.opengl.util.FPSAnimator;

import javax.media.opengl.*;
import javax.media.opengl.awt.GLCanvas;
import javax.media.opengl.glu.GLU;
import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;

/**
* @version 2010-nov-13
*/

public class JOGLTest
{
public static void main(String[] args)
{
JFrame frame = new JFrame("JOGL test");
frame.setSize(640, 480);

GLProfile glProfile = GLProfile.get(GLProfile.GL2);
GLCapabilities glCapabilities = new GLCapabilities(glProfile);

GLCanvas canvas = new GLCanvas(glCapabilities);
frame.add(canvas);

canvas.addGLEventListener(new JOGLRenderer());

AnimatorBase animator = new FPSAnimator(canvas, 60);
animator.add(canvas);
animator.start();

frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});

frame.setVisible(true);
}

private static class JOGLRenderer implements GLEventListener
{
@Override
public void init(GLAutoDrawable drawable)
{
GL2 gl = drawable.getGL().getGL2();

gl.glShadeModel(GL2.GL_SMOOTH);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glClearDepth(1.0f);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(GL.GL_LEQUAL);
gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);


// Create vertex data
float[] vertexData = new float[]
{
0.75f, 0.25f, -2.0f, 1.0f, 0.0f, 0.0f, 1.0f,
0.75f, 0.75f, -2.0f, 0.0f, 1.0f, 0.0f, 1.0f,
0.25f, 0.25f, -2.0f, 0.0f, 0.0f, 1.0f, 1.0f,
0.25f, 0.75f, -2.0f, 0.5f, 0.5f, 0.5f, 1.0f
};


ByteBuffer vertexByteBuffer = ByteBuffer.allocateDirect(7 * 4 * 4);
FloatBuffer vertexBuffer = vertexByteBuffer.asFloatBuffer();
vertexBuffer.put(vertexData);


// Create vertex buffer
int[] vertexBufferId = new int[1];
gl.glGenBuffers(1, vertexBufferId, 0);
gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, vertexBufferId[0]);
gl.glBufferData(GL2.GL_ARRAY_BUFFER, 1024, null, GL2.GL_DYNAMIC_DRAW);

// Load vertex data into vertex buffer
gl.glBufferSubData(GL2.GL_ARRAY_BUFFER, 0, vertexByteBuffer.capacity(), vertexByteBuffer);


// Create index data
int[] indexData = new int[]
{
0, 1, 2, 2, 1, 3
};

ByteBuffer indexByteBuffer = ByteBuffer.allocateDirect(6 * 4);
IntBuffer indexBuffer = indexByteBuffer.asIntBuffer();
indexBuffer.put(indexData);


// Create index buffer
int[] indexBufferId = new int[1];
gl.glGenBuffers(1, indexBufferId, 0);
gl.glBindBuffer(GL2.GL_ELEMENT_ARRAY_BUFFER, indexBufferId[0]);
gl.glBufferData(GL2.GL_ELEMENT_ARRAY_BUFFER, 1024, null, GL2.GL_DYNAMIC_DRAW);

// Load index data into index buffer
gl.glBufferSubData(GL2.GL_ELEMENT_ARRAY_BUFFER, 0, indexByteBuffer.capacity(), indexByteBuffer);
}

@Override
public void dispose(GLAutoDrawable drawable)
{
}

@Override
public void display(GLAutoDrawable drawable)
{
GL2 gl = drawable.getGL().getGL2();

gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();


/*

This rendered a purple quad

gl.glBegin(GL2.GL_TRIANGLES);
gl.glColor3f(0.5f ,0.0f, 0.5f);
gl.glVertex3f(0.75f, 0.25f, -2);
gl.glVertex3f(0.75f, 0.75f, -2);
gl.glVertex3f(0.25f, 0.25f, -2);

gl.glVertex3f(0.25f, 0.25f, -2);
gl.glVertex3f(0.75f, 0.75f, -2);
gl.glVertex3f(0.25f, 0.75f, -2);
gl.glEnd();
*/


// this below renders nothing

int stride = 7 * 4;

gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL2.GL_COLOR_ARRAY);

gl.glVertexPointer(3, GL2.GL_FLOAT, stride, 0);
gl.glColorPointer(4, GL2.GL_FLOAT, stride, 3 * 4);

gl.glDrawRangeElements(GL2.GL_TRIANGLES, 0, 5, 6, GL2.GL_UNSIGNED_INT, 0);
// gl.glDrawElements(GL2.GL_TRIANGLES, 6, GL2.GL_UNSIGNED_INT, 0);

// glGetError returns 0
int error = gl.glGetError();

gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL2.GL_COLOR_ARRAY);
}

@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
{
GL2 gl = drawable.getGL().getGL2();
GLU glu = new GLU();

gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();

gl.glViewport(0, 0, width, height);

gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45.0f, (float) width / (float) height, 0.1f, 100.0f);

gl.glMatrixMode(GL2.GL_MODELVIEW);
}
}
}



Share this post


Link to post
Share on other sites
LizardCPP    206
Ok I solved it myself and the problem lies in how one should work with java.nio.Buffer. I have to call the order() method on the ByteBuffer with ByteOrder.nativeOrder(). Then it works!

Full working source:

import com.jogamp.opengl.util.AnimatorBase;
import com.jogamp.opengl.util.FPSAnimator;

import javax.media.opengl.*;
import javax.media.opengl.awt.GLCanvas;
import javax.media.opengl.glu.GLU;
import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;

/**
* @version 2010-nov-13
*/

public class JOGLTest
{
public static void main(String[] args)
{
JFrame frame = new JFrame("JOGL test");
frame.setSize(640, 480);

GLProfile glProfile = GLProfile.get(GLProfile.GL2);
GLCapabilities glCapabilities = new GLCapabilities(glProfile);

GLCanvas canvas = new GLCanvas(glCapabilities);
frame.add(canvas);

canvas.addGLEventListener(new JOGLRenderer());

AnimatorBase animator = new FPSAnimator(canvas, 60);
animator.add(canvas);
animator.start();

frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});

frame.setVisible(true);
}

private static class JOGLRenderer implements GLEventListener
{
@Override
public void init(GLAutoDrawable drawable)
{
GL2 gl = drawable.getGL().getGL2();

gl.glShadeModel(GL2.GL_SMOOTH);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glClearDepth(1.0f);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(GL.GL_LEQUAL);
gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);


// Create vertex data
float[] vertexData = new float[]
{
0.75f, 0.25f, -2.0f, 1.0f, 0.0f, 0.0f, 1.0f,
0.75f, 0.75f, -2.0f, 0.0f, 1.0f, 0.0f, 1.0f,
0.25f, 0.25f, -2.0f, 0.0f, 0.0f, 1.0f, 1.0f,
0.25f, 0.75f, -2.0f, 0.5f, 0.5f, 0.5f, 1.0f
};


ByteBuffer vertexByteBuffer = ByteBuffer.allocateDirect(7 * 4 * 4);
vertexByteBuffer.order(ByteOrder.nativeOrder()); // <-- this line was missing
FloatBuffer vertexBuffer = vertexByteBuffer.asFloatBuffer();
vertexBuffer.put(vertexData);


// Create vertex buffer
int[] vertexBufferId = new int[1];
gl.glGenBuffers(1, vertexBufferId, 0);
gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, vertexBufferId[0]);
gl.glBufferData(GL2.GL_ARRAY_BUFFER, 1024, null, GL2.GL_DYNAMIC_DRAW);

// Load vertex data into vertex buffer
gl.glBufferSubData(GL2.GL_ARRAY_BUFFER, 0, vertexByteBuffer.capacity(), vertexByteBuffer);


// Create index data
int[] indexData = new int[]
{
0, 1, 2, 2, 1, 3
};

ByteBuffer indexByteBuffer = ByteBuffer.allocateDirect(6 * 4);
indexByteBuffer.order(ByteOrder.nativeOrder()); // <- this line was missing
IntBuffer indexBuffer = indexByteBuffer.asIntBuffer();
indexBuffer.put(indexData);


// Create index buffer
int[] indexBufferId = new int[1];
gl.glGenBuffers(1, indexBufferId, 0);
gl.glBindBuffer(GL2.GL_ELEMENT_ARRAY_BUFFER, indexBufferId[0]);
gl.glBufferData(GL2.GL_ELEMENT_ARRAY_BUFFER, 1024, null, GL2.GL_DYNAMIC_DRAW);

// Load index data into index buffer
gl.glBufferSubData(GL2.GL_ELEMENT_ARRAY_BUFFER, 0, indexByteBuffer.capacity(), indexByteBuffer);
}

@Override
public void dispose(GLAutoDrawable drawable)
{
}

@Override
public void display(GLAutoDrawable drawable)
{
GL2 gl = drawable.getGL().getGL2();

gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();


/*

This rendered a purple quad

gl.glBegin(GL2.GL_TRIANGLES);
gl.glColor3f(0.5f ,0.0f, 0.5f);
gl.glVertex3f(0.75f, 0.25f, -2);
gl.glVertex3f(0.75f, 0.75f, -2);
gl.glVertex3f(0.25f, 0.25f, -2);

gl.glVertex3f(0.25f, 0.25f, -2);
gl.glVertex3f(0.75f, 0.75f, -2);
gl.glVertex3f(0.25f, 0.75f, -2);
gl.glEnd();
*/


int stride = 7 * 4;

gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL2.GL_COLOR_ARRAY);

gl.glVertexPointer(3, GL2.GL_FLOAT, stride, 0);
gl.glColorPointer(4, GL2.GL_FLOAT, stride, 3 * 4);

gl.glDrawRangeElements(GL2.GL_TRIANGLES, 0, 5, 6, GL2.GL_UNSIGNED_INT, 0);
// gl.glDrawElements(GL2.GL_TRIANGLES, 6, GL2.GL_UNSIGNED_INT, 0);

// glGetError returns 0
int error = gl.glGetError();

gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL2.GL_COLOR_ARRAY);
}

@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
{
GL2 gl = drawable.getGL().getGL2();
GLU glu = new GLU();

gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();

gl.glViewport(0, 0, width, height);

gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45.0f, (float) width / (float) height, 0.1f, 100.0f);

gl.glMatrixMode(GL2.GL_MODELVIEW);
}
}
}


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  

  • Similar Content

    • By Zaphyk
      I am developing my engine using the OpenGL 3.3 compatibility profile. It runs as expected on my NVIDIA card and on my Intel Card however when I tried it on an AMD setup it ran 3 times worse than on the other setups. Could this be a AMD driver thing or is this probably a problem with my OGL code? Could a different code standard create such bad performance?
    • By Kjell Andersson
      I'm trying to get some legacy OpenGL code to run with a shader pipeline,
      The legacy code uses glVertexPointer(), glColorPointer(), glNormalPointer() and glTexCoordPointer() to supply the vertex information.
      I know that it should be using setVertexAttribPointer() etc to clearly define the layout but that is not an option right now since the legacy code can't be modified to that extent.
      I've got a version 330 vertex shader to somewhat work:
      #version 330 uniform mat4 osg_ModelViewProjectionMatrix; uniform mat4 osg_ModelViewMatrix; layout(location = 0) in vec4 Vertex; layout(location = 2) in vec4 Normal; // Velocity layout(location = 3) in vec3 TexCoord; // TODO: is this the right layout location? out VertexData { vec4 color; vec3 velocity; float size; } VertexOut; void main(void) { vec4 p0 = Vertex; vec4 p1 = Vertex + vec4(Normal.x, Normal.y, Normal.z, 0.0f); vec3 velocity = (osg_ModelViewProjectionMatrix * p1 - osg_ModelViewProjectionMatrix * p0).xyz; VertexOut.velocity = velocity; VertexOut.size = TexCoord.y; gl_Position = osg_ModelViewMatrix * Vertex; } What works is the Vertex and Normal information that the legacy C++ OpenGL code seem to provide in layout location 0 and 2. This is fine.
      What I'm not getting to work is the TexCoord information that is supplied by a glTexCoordPointer() call in C++.
      Question:
      What layout location is the old standard pipeline using for glTexCoordPointer()? Or is this undefined?
       
      Side note: I'm trying to get an OpenSceneGraph 3.4.0 particle system to use custom vertex, geometry and fragment shaders for rendering the particles.
    • By markshaw001
      Hi i am new to this forum  i wanted to ask for help from all of you i want to generate real time terrain using a 32 bit heightmap i am good at c++ and have started learning Opengl as i am very interested in making landscapes in opengl i have looked around the internet for help about this topic but i am not getting the hang of the concepts and what they are doing can some here suggests me some good resources for making terrain engine please for example like tutorials,books etc so that i can understand the whole concept of terrain generation.
       
    • By KarimIO
      Hey guys. I'm trying to get my application to work on my Nvidia GTX 970 desktop. It currently works on my Intel HD 3000 laptop, but on the desktop, every bind textures specifically from framebuffers, I get half a second of lag. This is done 4 times as I have three RGBA textures and one depth 32F buffer. I tried to use debugging software for the first time - RenderDoc only shows SwapBuffers() and no OGL calls, while Nvidia Nsight crashes upon execution, so neither are helpful. Without binding it runs regularly. This does not happen with non-framebuffer binds.
      GLFramebuffer::GLFramebuffer(FramebufferCreateInfo createInfo) { glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); textures = new GLuint[createInfo.numColorTargets]; glGenTextures(createInfo.numColorTargets, textures); GLenum *DrawBuffers = new GLenum[createInfo.numColorTargets]; for (uint32_t i = 0; i < createInfo.numColorTargets; i++) { glBindTexture(GL_TEXTURE_2D, textures[i]); GLint internalFormat; GLenum format; TranslateFormats(createInfo.colorFormats[i], format, internalFormat); // returns GL_RGBA and GL_RGBA glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, createInfo.width, createInfo.height, 0, format, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); DrawBuffers[i] = GL_COLOR_ATTACHMENT0 + i; glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, textures[i], 0); } if (createInfo.depthFormat != FORMAT_DEPTH_NONE) { GLenum depthFormat; switch (createInfo.depthFormat) { case FORMAT_DEPTH_16: depthFormat = GL_DEPTH_COMPONENT16; break; case FORMAT_DEPTH_24: depthFormat = GL_DEPTH_COMPONENT24; break; case FORMAT_DEPTH_32: depthFormat = GL_DEPTH_COMPONENT32; break; case FORMAT_DEPTH_24_STENCIL_8: depthFormat = GL_DEPTH24_STENCIL8; break; case FORMAT_DEPTH_32_STENCIL_8: depthFormat = GL_DEPTH32F_STENCIL8; break; } glGenTextures(1, &depthrenderbuffer); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); glTexImage2D(GL_TEXTURE_2D, 0, depthFormat, createInfo.width, createInfo.height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthrenderbuffer, 0); } if (createInfo.numColorTargets > 0) glDrawBuffers(createInfo.numColorTargets, DrawBuffers); else glDrawBuffer(GL_NONE); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) std::cout << "Framebuffer Incomplete\n"; glBindFramebuffer(GL_FRAMEBUFFER, 0); width = createInfo.width; height = createInfo.height; } // ... // FBO Creation FramebufferCreateInfo gbufferCI; gbufferCI.colorFormats = gbufferCFs.data(); gbufferCI.depthFormat = FORMAT_DEPTH_32; gbufferCI.numColorTargets = gbufferCFs.size(); gbufferCI.width = engine.settings.resolutionX; gbufferCI.height = engine.settings.resolutionY; gbufferCI.renderPass = nullptr; gbuffer = graphicsWrapper->CreateFramebuffer(gbufferCI); // Bind glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); // Draw here... // Bind to textures glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, textures[0]); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, textures[1]); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, textures[2]); glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); Here is an extract of my code. I can't think of anything else to include. I've really been butting my head into a wall trying to think of a reason but I can think of none and all my research yields nothing. Thanks in advance!
    • By Adrianensis
      Hi everyone, I've shared my 2D Game Engine source code. It's the result of 4 years working on it (and I still continue improving features ) and I want to share with the community. You can see some videos on youtube and some demo gifs on my twitter account.
      This Engine has been developed as End-of-Degree Project and it is coded in Javascript, WebGL and GLSL. The engine is written from scratch.
      This is not a professional engine but it's for learning purposes, so anyone can review the code an learn basis about graphics, physics or game engine architecture. Source code on this GitHub repository.
      I'm available for a good conversation about Game Engine / Graphics Programming
  • Popular Now