Ejemplo n.º 1
0
AnimSprite::AnimSprite(const char* a_cpTexture, GLFWwindow* window)
{
	GameWindow = window;
	m_dElapsedTime = 0;
	
	m_v3Position = Vector3(g_gl_width/2, g_gl_height/2, 0);

	LoadVertShader("./resources/VertexShader.glsl");
	LoadFragShader("./resources/FragmentShader.glsl");
	LinkShaders();
	GLint uvAttrib = glGetAttribLocation(m_ShaderProgram, "texcoord");
	glEnableVertexAttribArray(uvAttrib);
	matrix_location = glGetUniformLocation(m_ShaderProgram, "matrix");

	LoadSlices(a_cpTexture);
	LoadAnimations(m_atlas.sAnimations.c_str());
	LoadTexture(m_atlas.sSheet.c_str());

	m_dFrameDuration = (1.0/5.0);
	m_sCurrentAnimation = "move N";
	m_sCurrentSlice = "move N 0";
	iCurrentFrame = 0;
	iLoopMarker = 0;
	currentCycle = LOOP;
	m_texSize = m_atlas.v2Size;

	SetSlice();
	UVSetup();

}
Ejemplo n.º 2
0
Sprite::Sprite(const char* a_pTexture, int a_iWidth, int a_iHeight, Vector4 a_v4Color, GLFWwindow* window) {

	//load in the shaders using the new functions in quad
	GameWindow = window;

	LoadVertShader("../resources/VertexShader.glsl");
	LoadFragShader("../resources/FragmentShader.glsl");
	LinkShaders();

	GLuint uvAttrib = glGetAttribLocation(m_ShaderProgram, "texcoord");
	glEnableVertexAttribArray(uvAttrib);
	matrix_location = glGetUniformLocation(m_ShaderProgram, "matrix");
	LoadTexture(a_pTexture);

	m_v4SpriteColor = a_v4Color;

	m_aoVerts[0].Color = m_v4SpriteColor;
	m_aoVerts[1].Color = m_v4SpriteColor;
	m_aoVerts[2].Color = m_v4SpriteColor;
	m_aoVerts[3].Color = m_v4SpriteColor;

	m_v2Scale = Vector2::Vector2(a_iWidth, a_iHeight);

	m_v3Position = Vector3::Vector3(g_gl_width / 2, g_gl_height / 2, 0.0f);
}
Ejemplo n.º 3
0
GameEntity::GameEntity( const char* a_pSpriteSheet, GLFWwindow * window)
{
	GameWindow = window;
	elapsedTime = 0;
	LoadVertShader("./Resources/LoadVertexShader.glsl");
	LoadFragShader("./Resources/LoadFragmentShader.glsl");
	LinkShaders();
	GLint uvAttrib = glGetAttribLocation(m_ShaderProgram,"texcoord");
	glEnableVertexAttribArray(uvAttrib);
	matrix_location = glGetUniformLocation (m_ShaderProgram, "matrix");
	LoadSprites(a_pSpriteSheet);
	LoadAnimations(atlas.sAnimations.c_str());
	LoadTexture(atlas.sSheet.c_str());


	m_dFrames = (1.0/15.0);
	currentAnimation = "Idle";
	currentSprite = "Idle_01";
	currentFrame = 0;
	currentPlayType = SINGLE;
	m_uvScale.m_fX = atlas.v2Size.m_fY;
	m_uvScale.m_fY	= atlas.v2Size.m_fX;
	SetSprite();
	SetUVData();
	iFacing = "Right"; //flag for facing


}
Ejemplo n.º 4
0
Sprite::Sprite() {
	srand(time(NULL));
	LoadVertShader("../resources/VertexShader.glsl");
	LoadFragShader("../resources/FragmentShader.glsl");
	LinkShaders();

	m_v4SpriteColor = Vector4::Vector4(1.0f, 1.0f, 1.0f, 1.0f);

	m_aoVerts[0].Color = m_v4SpriteColor;
	m_aoVerts[1].Color = m_v4SpriteColor;
	m_aoVerts[2].Color = m_v4SpriteColor;
	m_aoVerts[3].Color = m_v4SpriteColor;

	m_aoVerts[0].UV = Vector2::Vector2(1.0f, 0.0f);
	m_aoVerts[1].UV = Vector2::Vector2(0.0f, 1.0f);
	m_aoVerts[2].UV = Vector2::Vector2(1.0f, 0.0f);
	m_aoVerts[3].UV = Vector2::Vector2(1.0f, 1.0f);

	m_v2Scale = Vector2::Vector2(1.0f, 1.0f);

	m_v3Position = Vector3::Vector3(g_gl_width / 2, g_gl_height / 2, 0.0f);
}
AnimatedSprite::AnimatedSprite(const char* a_pSpriteSheet, GLFWwindow * window) {
	GameWindow = window;
	m_dElapsedTime = 0;
	LoadVertShader("../resources/VertexShader.glsl");
	LoadFragShader("../resources/FragShader.glsl");
	LinkShaders();

	GLint uvAttrib = glGetAttribLocation(m_ShaderProgram, "texcoord");
	glEnableVertexAttribArray(uvAttrib);
	matrix_location = glGetUniformLocation(m_ShaderProgram, "matrix");
	LoadSprites(a_pSpriteSheet);
	LoadAnimations(atlas.sAnimations.c_str());

	m_dFrames = (1.0 / 15.0);
	sCurrentAnimation = "";
	sCurrentSprite ="idle 0";
	CurrentPlayType = SINGLE;
	m_uvScale.m_fX = atlas.v2Size.m_fY;
	m_uvScale.m_fY = atlas.v2Size.m_fX;
	SetSprite();
	SetUVData();
}
Ejemplo n.º 6
0
AnimatedSprite::AnimatedSprite( const char* a_pSpriteSheet, GLFWwindow * window)
{
	//Make GameWindow equal window
	GameWindow = window;
	//Make elapsedTime equal 0
	elapsedTime = 0;
	//Load the Shaders
	LoadVertShader("resources/VertexShader.glsl");
	LoadFragShader("resources/FragmentShader.glsl");
	//Link the Shaders
	LinkShaders();
	//Make a GLint and equal it to glGetAttribLocation
	GLint uvAttrib = glGetAttribLocation(m_ShaderProgram,"texcoord");
	//Call glEnableVertexAttribArray with the required data
	glEnableVertexAttribArray(uvAttrib);
	//Make matrix_location equal to glGetUniformLocation
	matrix_location = glGetUniformLocation (m_ShaderProgram, "matrix");
	
	//Load the Sprites,Animations, and Texture
	LoadSprites(a_pSpriteSheet);
	//
	LoadTexture(atlas.sSheet.c_str());
	//Make m_dFrames equal to 1 divided by 2
	m_dFrames = (1.0/2.0);
	//Make currentAnimation equal nothing
	currentAnimation = "";
	//Make the currentSprite equal idle
	//currentSprite = "idle";
	//Make the currentFrame equal 0
	currentFrame = 0;
	//Make uvScale equale the atlas size
	m_uvScale.m_fX = atlas.v2Size.m_fY;
	m_uvScale.m_fY	= atlas.v2Size.m_fX;
	//Call SetSprite
	SetSprite();
	//call SetUVData
	SetUVData();
}
Ejemplo n.º 7
0
Sprite::Sprite( const char* a_pTexture, int a_iWidth, int a_iHeight, Vector4 a_v4Color , GLFWwindow * window)
{

	GameWindow = window;
	//Default Shaders for Default constructor

/*	const char * VertexShader =	// Vertex Shaders deal with objects in 3D space
		"#version 330\n"
		"in vec3 position;"
		"in vec4 color;"
		"in vec2 texcoord;"
		"out vec2 UV;"
		"out vec4 vColor;"
		"uniform mat4 matrix;" // our matrix
		"void main() {"
		"	UV = texcoord;"
		"	gl_Position = matrix * vec4 (position, 1.0);"
		"	vColor = color;"
		"}";

	const char * FragmentShader =	// Fragment Shaders dela with pixel data
		"#version 330\n"
		"in vec4 vColor;"
		"in vec2 UV;"
		"out vec4 outColour;"
		"uniform sampler2D diffuseTexture;"
		"void main () {"
		"	outColour =  texture2D(diffuseTexture, UV) * vColor;"
		"}";
	// Compile Vertex Shader
	m_VertexShader = glCreateShader(GL_VERTEX_SHADER);
	glShaderSource(m_VertexShader, 1, &VertexShader, NULL);
	glCompileShader(m_VertexShader);
	printShaderInfoLog(m_VertexShader);

	// Compile Fragment Shader
	m_FragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
	glShaderSource(m_FragmentShader, 1, &FragmentShader, NULL);
	glCompileShader(m_FragmentShader);
	printShaderInfoLog(m_FragmentShader);
*/
	LoadVertShader("../resources/exampleVert.glsl");
	LoadFragShader("../resources/exampleFrag.glsl");
	LinkShaders();

	// Link Shaders into Shader Program
	m_ShaderProgram = glCreateProgram();

	glAttachShader(m_ShaderProgram, m_FragmentShader);
	glAttachShader(m_ShaderProgram, m_VertexShader);

	glLinkProgram(m_ShaderProgram);
	printProgramInfoLog(m_ShaderProgram);
	glUseProgram(m_ShaderProgram);

	m_v4SpriteColor = a_v4Color;

	m_aoVerts[0].Pos = Vector3(	-0.5f,  0.5f,  0.0f);
	m_aoVerts[1].Pos = Vector3(	0.5f,  0.5f,  0.0f);
	m_aoVerts[2].Pos = Vector3(	-0.5f,  -0.5f,  0.0f);
	m_aoVerts[3].Pos = Vector3(	0.5f,  -0.5f,  0.0f);
	

	m_aoVerts[0].Color = m_v4SpriteColor;
	m_aoVerts[1].Color = m_v4SpriteColor;
	m_aoVerts[2].Color = m_v4SpriteColor;
	m_aoVerts[3].Color = m_v4SpriteColor;



	m_aoVerts[0].UV = Vector2(0.0f,  0.0f);
	m_aoVerts[1].UV = Vector2(0.0f,  1.0f);
	m_aoVerts[2].UV = Vector2(1.0f,  0.0f);
	m_aoVerts[3].UV = Vector2(1.0f,  1.0f);

	GLuint elements[] =
	{
		0,1,2,3
	};

	//Gen Buffers
	glGenBuffers(1,&m_VBO);
	glGenBuffers(1,&m_EBO);
	glGenVertexArrays(1, &m_VAO);

	//Bind Buffers
	glBindVertexArray(m_VAO);
	glBindBuffer(GL_ARRAY_BUFFER, m_VBO);

	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_EBO);

	//Put Data into buffers
	glBufferData(GL_ARRAY_BUFFER, 4* sizeof(Vertex), m_aoVerts, GL_STATIC_DRAW);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elements), elements, GL_STATIC_DRAW);

	//Enable some attributes
	GLint posAttrib = glGetAttribLocation(m_ShaderProgram,"position");
	glEnableVertexAttribArray(posAttrib);
	GLint colAttrib = glGetAttribLocation(m_ShaderProgram,"color");
	glEnableVertexAttribArray(colAttrib);
	GLint uvAttrib = glGetAttribLocation(m_ShaderProgram,"texcoord");
	glEnableVertexAttribArray(uvAttrib);


	glVertexAttribPointer(posAttrib, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
	glVertexAttribPointer(colAttrib, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(3 * sizeof(float)));
	glVertexAttribPointer(uvAttrib, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(7 * sizeof(float)));

	glBindVertexArray(0);
	m_v3Position = Vector3(0,0,0);
	modelMatrix =new float[16];	
	float temp[]= 
	{
		1,0,0,0,
		0,1,0,0,
		0,0,1,0,
		0,0,0,1
	};
	memcpy(modelMatrix,temp,16*sizeof(float)); //not sure of a better way

	matrix_location = glGetUniformLocation (m_ShaderProgram, "matrix");

	m_uiTexture = 0;
	m_minUVCoords = Vector2( 0.f, 0.f );
	m_maxUVCoords = Vector2( 1.f, 1.f );
	m_uvScale = Vector2( 1.f, 1.f );
	m_uvOffset = Vector2( 0.f, 0.f );

	m_uSourceBlendMode	= GL_SRC_ALPHA;
	m_uDestinationBlendMode = GL_ONE_MINUS_SRC_ALPHA;

	glGenTextures(1, &m_uiTexture);
	glActiveTexture (GL_TEXTURE0);

	int width, height;
	unsigned char* image = SOIL_load_image(a_pTexture, &width, &height, 0, SOIL_LOAD_RGBA);
	glBindTexture( GL_TEXTURE_2D,m_uiTexture);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
	SOIL_free_image_data(image);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	tex_loc = glGetUniformLocation (m_ShaderProgram, "diffuseTexture");
	glUseProgram (m_ShaderProgram);
	glUniform1i (tex_loc, 0); // use active texture 0

}
Ejemplo n.º 8
0
Sprite::Sprite( const char* a_pTexture, int a_iWidth, int a_iHeight, tbyte::Vector4 a_v4Color ,GLFWwindow * window)
{

	GameWindow = window;
	
	LoadVertShader("../resources/exampleVert.glsl");
	LoadFragShader("../resources/exampleFrag.glsl");
	LinkShaders();

	m_v4SpriteColor = a_v4Color;

	m_aoVerts[0].Pos = tbyte::Vector3(	-0.5f,  0.5f,  0.0f);
	m_aoVerts[1].Pos = tbyte::Vector3(	0.5f,  0.5f,  0.0f);
	m_aoVerts[2].Pos = tbyte::Vector3(	-0.5f,  -0.5f,  0.0f);
	m_aoVerts[3].Pos = tbyte::Vector3(	0.5f,  -0.5f,  0.0f);
	
	/*
	m_aoVerts[0].Color = tbyte::Vector4(1.0f,  0.0f,  0.0f, 1.0f);
	m_aoVerts[1].Color = tbyte::Vector4(0.0f,  1.0f,  0.0f, 1.0f);
	m_aoVerts[2].Color = tbyte::Vector4(0.0f,  0.0f,  1.0f, 1.0f);
	m_aoVerts[3].Color = tbyte::Vector4(1.0f,  1.0f,  1.0f, 1.0f);
	*/


	m_aoVerts[0].Color = m_v4SpriteColor;
	m_aoVerts[1].Color = m_v4SpriteColor;
	m_aoVerts[2].Color = m_v4SpriteColor;
	m_aoVerts[3].Color = m_v4SpriteColor;



	m_aoVerts[0].UV = tbyte::Vector2(0.0f,  0.0f);
	m_aoVerts[1].UV = tbyte::Vector2(0.0f,  1.0f);
	m_aoVerts[2].UV = tbyte::Vector2(1.0f,  0.0f);
	m_aoVerts[3].UV = tbyte::Vector2(1.0f,  1.0f);

	GLuint elements[] =
	{
		0,1,2,3
	};

	//Gen Buffers
	glGenBuffers(1,&m_VBO);
	glGenBuffers(1,&m_EBO);
	glGenVertexArrays(1, &m_VAO);

	//Bind Buffers
	glBindVertexArray(m_VAO);
	glBindBuffer(GL_ARRAY_BUFFER, m_VBO);

	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_EBO);

	//Put Data into buffers
	glBufferData(GL_ARRAY_BUFFER, 4* sizeof(Vertex), m_aoVerts, GL_STATIC_DRAW);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elements), elements, GL_STATIC_DRAW);

	//Enable some attributes
	GLint posAttrib = glGetAttribLocation(m_ShaderProgram,"position");
	glEnableVertexAttribArray(posAttrib);
	GLint colAttrib = glGetAttribLocation(m_ShaderProgram,"color");
	glEnableVertexAttribArray(colAttrib);
	GLint uvAttrib = glGetAttribLocation(m_ShaderProgram,"texcoord");
	glEnableVertexAttribArray(uvAttrib);


	glVertexAttribPointer(posAttrib, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
	glVertexAttribPointer(colAttrib, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(3 * sizeof(float)));
	glVertexAttribPointer(uvAttrib, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(7 * sizeof(float)));

	glBindVertexArray(0);
	m_v2Scale = tbyte::Vector2(a_iWidth,a_iHeight);
	m_v3Position = tbyte::Vector3(1024/2,768/2,0);
	
	modelMatrix = new tbyte::Matrix4();
	viewMatrix = new tbyte::Matrix4();

	*modelMatrix  = *viewMatrix = Matrix4::IdentityMatrix();
	
	ViewLookAt(tbyte::Vector4(0,0,0,0),tbyte::Vector4(0,0,.5,0),tbyte::Vector4(0,1,0,0), viewMatrix);

	modelMatrix->m_afArray[12] = m_v3Position.m_fX;
	modelMatrix->m_afArray[13] = m_v3Position.m_fY;
	modelMatrix->m_afArray[14] = m_v3Position.m_fZ;


	matrix_location = glGetUniformLocation (m_ShaderProgram, "matrix");


	m_uiTexture = 0;
	m_minUVCoords = tbyte::Vector2( 0.f, 0.f );
	m_maxUVCoords = tbyte::Vector2( 1.f, 1.f );
	m_uvScale = tbyte::Vector2( 1.f, 1.f );
	m_uvOffset = tbyte::Vector2( 0.f, 0.f );

	m_uSourceBlendMode	= GL_SRC_ALPHA;
	m_uDestinationBlendMode = GL_ONE_MINUS_SRC_ALPHA;

	glGenTextures(1, &m_uiTexture);
	glActiveTexture (GL_TEXTURE0);

	int width, height;
	unsigned char* image = SOIL_load_image(a_pTexture, &width, &height, 0, SOIL_LOAD_RGBA);
	glBindTexture( GL_TEXTURE_2D,m_uiTexture);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
	SOIL_free_image_data(image);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);


	tex_location = glGetUniformLocation (m_ShaderProgram, "diffuseTexture");
	
	proj_location = glGetUniformLocation (m_ShaderProgram, "projection");
	
	view_location = glGetUniformLocation (m_ShaderProgram, "view");

}