Jump to content

  • Log In with Google      Sign In   
  • Create Account

Calling all IT Pros from Canada and Australia.. we need your help! Support our site by taking a quick sponsored surveyand win a chance at a $50 Amazon gift card. Click here to get started!


GameGeezer

Member Since 07 Feb 2010
Offline Last Active Mar 07 2015 02:19 PM

Topics I've Started

FBO only renders to the first target

25 January 2015 - 09:33 PM

Hey, I'm trying to render to multiple targets using a frame buffer object, but as of now only the first target is being rendered to. If I render either of the other two buffers to the screen it's a white wash.

 

It does work for the first and as far as I can tell I'm not treating the other two targets any differently, so I'm having a bit of trouble deciphering where the root of this problem is. If anyone could point me in the right direction that would be great!

 

Oh and I'm using the fixed function pipeline as a placeholder to draw the texture since it was a quick solution.

 

Renderer:

public class DeferredRenderer {

    public static final int POSITION_BUFFER_BINDING = 0;
    public static final int NORMAL_BUFFER_BINDING = 1;
    public static final int DIFFUSE_BUFFER_BINDING = 2;
    public static final int SCREEN_BUFFER_BINDING = 3;

    private final Texture positionBuffer;
    private final Texture normalBuffer;
    private final Texture diffuseBuffer;

    private final Texture screenTexture;

    private final FBO fbo;
    private final RBO fboDepthBuffer;

    public DeferredRenderer(final int width, final int height) throws GraphicsException{

        GL11.glEnable(GL11.GL_DEPTH_TEST);
        GL11.glEnable(GL11.GL_CULL_FACE); 

        positionBuffer = new Texture(width, height, POSITION_BUFFER_BINDING, OGLColorType.RGBA16F);
        normalBuffer = new Texture(width, height, NORMAL_BUFFER_BINDING, OGLColorType.RGBA16F);
        diffuseBuffer = new Texture(width, height, DIFFUSE_BUFFER_BINDING, OGLColorType.RGBA16F);

        screenTexture = new Texture(width, height, SCREEN_BUFFER_BINDING, OGLColorType.RGBA8);

        fbo = new FBO();
        fboDepthBuffer = new RBO(width, height, AttachmentType.DEPTH_ATTACHMENT);

        fbo.bind();
        fboDepthBuffer.bind();

        positionBuffer.attachToFBO(AttachmentType.COLOR_ATTACHMENT0);
        normalBuffer.attachToFBO(AttachmentType.COLOR_ATTACHMENT1);
        diffuseBuffer.attachToFBO(AttachmentType.COLOR_ATTACHMENT2);

        final IntBuffer buffer = BufferUtils.createIntBuffer(3);
        buffer.put(0, AttachmentType.COLOR_ATTACHMENT0.ID);
        buffer.put(1, AttachmentType.COLOR_ATTACHMENT1.ID);
        buffer.put(2, AttachmentType.COLOR_ATTACHMENT2.ID);

        buffer.rewind();
        // Creates an array of buffers that the fragment shader will output to
        GL20.glDrawBuffers(buffer);

        if(!fbo.checkForErrors()) {
            throw new GraphicsException("Could not compile FBO");
        }

        fboDepthBuffer.unbind();
        fbo.unbind();
    }

    public void beginDrawing() {

        fbo.bind();

        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

    }

    public void endDrawing() {

        fbo.unbind();

        diffuseBuffer.bind();
        GL11.glBegin(GL11.GL_QUADS);

        GL11.glTexCoord2f(0.0f, 0.0f);
        GL11.glVertex3f(-1.0f, -1.0f, 0.0f); // The bottom left corner

        GL11.glTexCoord2f(0.0f, 1.0f);
        GL11.glVertex3f(-1.0f, 1.0f, 0.0f); // The top left corner

        GL11.glTexCoord2f(1.0f, 1.0f);
        GL11.glVertex3f(1.0f, 1.0f, 0.0f); // The top right corner

        GL11.glTexCoord2f(1.0f, 0.0f);
        GL11.glVertex3f(1.0f, -1.0f, 0.0f); // The bottom right corner

        GL11.glEnd();

        diffuseBuffer.unbind();
    }

    public void destroy() {

        positionBuffer.destroy();
        normalBuffer.destroy();
        diffuseBuffer.destroy();
    }
}

Vertex shader:

#version 330 core
uniform mat4 u_projectionMatrix;
uniform mat4 u_viewMatrix;
uniform mat4 u_modelMatrix;

in vec4 in_Position;
in vec3 in_Normal;
in vec2 in_TextureCoord;

out vec4 pass_Position;
out vec4 pass_Normal;
out vec2 pass_TextureCoord;


void main(void) {

    mat4 mvp = u_projectionMatrix * u_viewMatrix * u_modelMatrix;

    pass_Position = mvp * in_Position;
    pass_Normal = vec4(normalize(mat3(mvp) * in_Normal), 1);

	pass_TextureCoord = in_TextureCoord;

	gl_Position = mvp * in_Position;
}

Fragment shader:

 

(I know I'm not passing the correct values, I just want to fix this problem and pass data through all the buffers before continuing on)

#version 330 core

uniform sampler2D texture_diffuse;

in vec4 pass_Position;
in vec4 pass_Normal;
in vec2 pass_TextureCoord;


void main(void) {

	vec4 texel = texture(texture_diffuse, pass_TextureCoord);

	gl_FragData[0] = texel;
	gl_FragData[1] = pass_Normal;
	gl_FragData[2] = texel;
}

Help with matrix rotation

15 May 2014 - 05:44 PM

Hey, I'm currently working on a project that requires me to create a bunch of objects, rotate them locally, then revolve them all around a point.

 

I have a parent Node that contains all the objects I create so my idea was to create each object, rotate it to my desired orientation, translate it, add it to the parent node, and then rotate the parent node and have it recursively rotate the children.

 

My problem is that with multiple rotations everything starts to go haywire. I've spent a couple of days on this and haven't made much progress so if someone could point me in the right direction that would be wonderful! 

 

I have a Matrix for the model and a Vector3 to keep track of the translation

	protected Matrix4f model = new Matrix4f();
	protected Vector3 translation = new Vector3();

This is the code I'm using to rotate the objects.

public SceneNode rotate(float rot, float rx, float ry, float rz) {
		for (Node<SceneNode> node : this.getSubnodes()) {
			((SceneNode) node).rotate(rot, rx, ry, rz);
		}
		model.rotate(rot, rx, ry, rz);
		return this;
	}
	
	public SceneNode rotateLocal(float rot, float rx, float ry, float rz) {
		
		for (Node<SceneNode> node : this.getSubnodes()) {
			((SceneNode) node).rotateLocal(rot, rx, ry, rz);
		}
		float x = getX();
		float y = getY();
		float z = getZ();
		
		model.translate(-x, -y, -z);
		model.rotate(rot, rx, ry, rz);
		model.translate(x, y, z);
		return this;
	}

this is the code I'm using to translate the objects

	public SceneNode translate(float x, float y, float z) {
		for (Node<SceneNode> node : this.getSubnodes()) {
			((SceneNode) node).translate(x, y, z);
		}
		model.translate(x, y, z);
		translation.set(x, y, z);
		return this;
	}
This is the code where I'm creating the child node(bondObject)and attaching it to the parent(parentNode)
bondObject.rotateLocal(angle, x, y, z);
bondObject.setTranslation(x, y, z);
        		        		
parentNode.attach(bondObject);

And I want to rotate it every frame like this

parentNode.rotateLocal(1, 1, 1, 0);

how to use static variables properly in c++

24 February 2013 - 09:51 AM

Hey, I've been getting an error "Undefined reference to  Game:: window." I was wondering how I would go about declaring a static variable, initializing it, and accessing it properly. Thanks for your time.

 

cc file:

sf::RenderWindow* const Game::getWindow(void){
        return Game::window;
    }

 

h file:

public:
 static sf::RenderWindow* const getWindow(void);
private:
static sf::RenderWindow* window;

Ray Sphere intersection

20 November 2012 - 12:48 PM

Using this tutorial:http://wiki.cgsociety.org/index.php/Ray_Sphere_Intersection. I wrote a method to test ray,sphere intersections:
However I'm unsure as to what the direction vector will consist of. It's apparent that the direction vector isn't angles so I'm assuming it's the slope of the line in each direction?

float RaySphere::intersects(Ray* ray){
Vector3f dist = this->position.x_sub(&(ray->startpos));

float a = ray->angle.dotProd(&(ray->angle));
float b = 2 * ray->angle.dotProd(&(ray->startpos));
float c = ray->startpos.dotProd(&(ray->startpos)) - this->radius_squared;

float disk = b * b - 4 * a * c;

//no roots
if(disk <0)
  return -1;

float distsqrt = sqrt(disk);
float q;

if(b < 0)
  q = (-b-distsqrt)/2.0;
else
  q = (-b+distsqrt)/2.0;

float t0 = q / a;
float t1 = c / q;

//if t0 > t1 then swap them.
if(t0 > t1)
{
  float temp = t0;
  t0 = t1;
  t1 = temp;
}
//the ray missed the sphere
if(t1 < 0)
  return -1;
//if t0<0 intersection is at t1
if(t0<0)
  return t1;
//else its at t0
return t0;
}

Linux development

18 October 2012 - 06:27 PM

I'm trying to set up a development environment on linux but I've run into an error where my ide recognizes the libraries and event goes to finish my line when I type in "glGenTextures," but throws a bunch of errors like these:

/home/william/programming/workspaces/cplusplus/Test2/main.cpp|49|error: undefined reference to 'glGenTextures'|
/home/william/programming/workspaces/cplusplus/Test2/main.cpp|50|error: undefined reference to 'glBindTexture'|
/home/william/programming/workspaces/cplusplus/Test2/main.cpp|58|error: undefined reference to 'glTexImage2D'|
/home/william/programming/workspaces/cplusplus/Test2/main.cpp|63|error: undefined reference to 'glEnable'|
/home/william/programming/workspaces/cplusplus/Test2/main.cpp|64|error: undefined reference to 'glEnable'|

I set up Opengl using this guy's tutorial(which was very comprehensive, I don't see anywhere I could have missed a step)
http://www.videotutorialsrock.com/opengl_tutorial/get_opengl_setup_linux/video.php

my usr/include/GL contains all the files show in the video.

I've tried compiling this in Code: blocks and with this guy's make file.

I assume its a problem with linking, but I'm having trouble resolve exactly what to do.

PARTNERS