Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


nkarasch

Member Since 01 Nov 2012
Offline Last Active Nov 01 2013 10:22 AM

#5017377 Passing attributes to shaders

Posted by nkarasch on 03 January 2013 - 11:57 PM

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.




#5015594 Miscellaneous OpenGL questions (mostly dealing with shaders)

Posted by nkarasch on 29 December 2012 - 07:49 PM

When the model loads for the first time,

		int vaoId = glGenVertexArrays();
		glBindVertexArray(vaoId);
		
		int vboVertexHandle = glGenBuffers();
		int vboNormalHandle = glGenBuffers();
		
		glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
		glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW);
		glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
		
		glBindBuffer(GL_ARRAY_BUFFER, vboNormalHandle);
		glBufferData(GL_ARRAY_BUFFER, normals, GL_STATIC_DRAW);
		glVertexAttribPointer(1, 3, GL_FLOAT, false, 0, 0);
		
		glBindBuffer(GL_ARRAY_BUFFER, 0);
		glBindVertexArray(0);
		return vaoId;

and every time it renders it runs

                glBindVertexArray(vao);
		glEnableVertexAttribArray(0);
		glEnableVertexAttribArray(1);

		glUseProgram(shaderProgram);
		glDrawArrays(GL_TRIANGLES, 0, model.getVertices().size() * 6);
		glUseProgram(0);
		glBindBuffer(GL_ARRAY_BUFFER, 0);
		glBindVertexArray(0);

It is amazing how a three letter acronym through me off. I'm having a weird issue where only one side of each model is being shaded but I'll figure it out.




#4996421 How should I implement a state based game?

Posted by nkarasch on 01 November 2012 - 10:00 PM

I would like to handle game states the way Slick does, without using Slick. I think that is the best solution.

I would want a state for the main menu, options screen, each level, game over and the ending.

I'm pretty new to developing games. I currently only have one "level" and I'm accessing it like this

public class StateHub {
public static void main(String[] args) {
  JFrame frame = new JFrame();
  frame.add(new LevelOne());
  frame.setVisible(true);
  frame.setSize(800, 600);
  frame.setResizable(false);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

For my last game I had a huge series of booleans changing what was drawn to the panel, it got unmanageable fast. Just trying to clean things up. Is there a simple way to turn this into a state-like system where I could do something like destroy the instance of LevelOne and add LevelTwo instead? Is there an easier solution?

Thanks a ton.


PARTNERS