Passing attributes to shaders

Started by
18 comments, last by _paf 11 years, 3 months ago

System.out.println(glGetShaderInfoLog(vertexShader, glGetProgrami(shaderProgram, GL_INFO_LOG_LENGTH)));

Isn't giving me anything, hmmm.

And yeah, I am going to move away from the built in matrix functions.

Also, I'm using Java so I don't think GLM is an option. LWJGL has appropriate tools built in though.

Thanks for the response

Advertisement

I am not entirely sure about this since i haven't used Opengl for a while but if i remember correctly, generating and binding then vao, vbo goes like this.


gluint vaoID;
gluint vboID;
glGenVertexArrays(1, &vaoID); // Create Vertex Array Object  
glBindVertexArray(vaoID); // Bind Vertex Array Object  
  
glGenBuffers(1, &vboID); // Generate Vertex Buffer Object  
glBindBuffer(GL_ARRAY_BUFFER, vboID[0]); // Bind Vertex Buffer Object  
I am not entirely sure about this since i haven't used Opengl for a while but if i remember correctly, generating and binding then vao, vbo goes like this.


gluint vaoID;
gluint vboID;
glGenVertexArrays(1, &vaoID); // Create Vertex Array Object  
glBindVertexArray(vaoID); // Bind Vertex Array Object  
  
glGenBuffers(1, &vboID); // Generate Vertex Buffer Object  
glBindBuffer(GL_ARRAY_BUFFER, vboID[0]); // Bind Vertex Buffer Object  

Mine looks different because I'm doing it in LWJGL. The gl functions are the same, you just don't have access to pointers in the same way so it ends up looking a bit different. You also have to pass chunks of data as FloatBuffers.

You need to call glGetShader with the shader object (not the program object with glGetProgram) to get the length.

Sorry about recommending the wrong language library; I was paying attention to the gl, not the language.

New C/C++ Build Tool 'Stir' (doesn't just generate Makefiles, it does the build): https://github.com/space222/stir

Is


gl_ModelViewProjectionMatrix

unknown by GSLS 3.3? Even


gl_Position = gl_ModelViewProjectionMatrix*gl_Vertex;

isn't working, it is definitely my problem line

Yes, it is. In 3.0 and newer, the built-in matrix stuff was dropped - glTranslate, glRotate and all their friends. So you'll have to have your own uniform matrix - it's not too hard to build yourself, there is tons of projection / lookat matrix code out there, and those are the two you most likely want to have.

Thanks. I got around to implementing my own matrices today, hasn't worked out so well so far but I know it's just errors in my logic

For your amusement:

">

You could read this http://www.arcsynthesis.org/gltut/

Rotation, perspective and translation matrices are explained there. You also have different space transformations too (model to world, word to view, etc). And quaternion rotation for when you get bored of matrices :D

It may not be easy to understand, depending on the familiarity you have with linear algebra (even then, the books starts to apply it to graphics so it may get complicated anyway).

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

Disclaimer: This code is an ugly mess that has been getting abused for a few days. It is not pretty, I'm aware. I'm just desperate to get it working, then the beautification process will occur.

Also, the delta time is no longer working as intended. I know how to fix it, but there is no point when I can't get rotations working.

I'm having a tough time here. My translations work perfectly. However, as soon as I start adding rotations in, things go nuts. X axis rotations alone are fine, Y axis alone are fine but when I have both activated I end up spinning and rolling out of control. I'm also pretty sure that the rotations are all more like revolutions around the original starting point.

Any insight would be great. I was stole this code http://www.lloydgoodall.com/tutorials/first-person-camera-control-with-lwjgl/, using the built in matrix stack and it worked great. A lot of the code below is ugly remnants of it


package karasch.lwjgl.utility;

import java.io.FileNotFoundException;
import java.io.IOException;
import karasch.lwjgl.entitysetup.IEntity;

import org.lwjgl.input.Mouse;
import org.lwjgl.util.vector.Matrix4f;
import org.lwjgl.util.vector.Vector3f;

public class View implements IEntity {

	private Vector3f position;
	private float x, y, z, yaw, pitch;
	private float moveSpeed, mouseSensitivity, deltaMoveSpeed;
	int dx, dy;
	static Matrix4f viewMatrix;

	public View(float x, float y, float z) throws FileNotFoundException,
			IOException {

		moveSpeed = 0.00001f;

		dx = Mouse.getDX();
		dy = Mouse.getDY();
		
		yaw = 0;
		pitch = 0;

		position = new Vector3f(x, y, z);
		mouseSensitivity = 0.0000025f;

		viewMatrix = new Matrix4f();
		viewMatrix.setIdentity();
	}

	// increment the camera's current yaw rotation
	public void yaw(float amount) {
		// increment the yaw by the amount param
		yaw += amount;
	}

	// increment the camera's current yaw rotation
	public void pitch(float amount) {
		// increment the pitch by the amount param
		pitch += amount;
	}
	
	public void applyTransformations() {
		viewMatrix.rotate(pitch, new Vector3f(1, 0, 0));
		viewMatrix.rotate(yaw, new Vector3f(0, 1, 0));
		viewMatrix.translate(position);
		System.out.println(viewMatrix);
	}

	public void update(int delta) {
		deltaMoveSpeed = moveSpeed * delta;

		dx = Mouse.getDX();
		dy = Mouse.getDY();

		this.yaw(dx * mouseSensitivity);
		this.pitch(dy * -mouseSensitivity);
		if (Input.dPressed) {
			strafeRight(deltaMoveSpeed);
		}

		if (Input.aPressed) {
			strafeLeft(deltaMoveSpeed);
		}

		if (Input.wPressed) {
			walkForward(deltaMoveSpeed);
		}

		if (Input.sPressed) {
			walkBackward(deltaMoveSpeed);
		}

		if (Input.controlPressed) {
			moveDown(deltaMoveSpeed);
		}

		if (Input.spacePressed) {
			moveUp(deltaMoveSpeed);
		}
	}

	public static Matrix4f getViewMatrix() {
		return viewMatrix;
	}

	// moves the camera forward relative to its current rotation (yaw)
	// moves the camera forward relative to its current rotation (yaw)
	public void walkForward(float distance) {
		position.x -= distance * (float) Math.sin(Math.toRadians(yaw));
		position.z += distance * (float) Math.cos(Math.toRadians(yaw));
	}

	// moves the camera backward relative to its current rotation (yaw)
	public void walkBackward(float distance) {
		position.x += distance * (float) Math.sin(Math.toRadians(yaw));
		position.z -= distance * (float) Math.cos(Math.toRadians(yaw));
	}

	public void moveUp(float distance) {
		position.y -= distance;

	}

	public void moveDown(float distance) {
		position.y += distance;

	}

	// strafes the camera left relitive to its current rotation (yaw)
	public void strafeLeft(float distance) {
		position.x -= distance * (float) Math.sin(Math.toRadians(yaw - 90));
		position.z += distance * (float) Math.cos(Math.toRadians(yaw - 90));
	}

	// strafes the camera right relitive to its current rotation (yaw)
	public void strafeRight(float distance) {
		position.x -= distance * (float) Math.sin(Math.toRadians(yaw + 90));
		position.z += distance * (float) Math.cos(Math.toRadians(yaw + 90));
	}

	public Vector3f getPosition() {
		return position;
	}

	public float getX() {
		return x;
	}

	public void setX(float x) {
		this.x = x;
	}

	public float getY() {
		return y;
	}

	public void setY(float y) {
		this.y = y;
	}

	public float getZ() {
		return z;
	}

	public void setZ(float z) {
		this.z = z;
	}

	@Override
	public void destroy() {
	}

	@Override
	public void render() {
		this.applyTransformations();
	}
}

Does just one rotation work as expected?

Try changing the order of the rotations, doing the yaw first and the pitch last.

Also, do you apply the transformations on an identity matrix each time you render the scene? I think it is necessary to do so, else you're doing translations over rotations over translations, etc.

This topic is closed to new replies.

Advertisement