void SpriteBatch::DrawSprite(unsigned int VBO, unsigned int IBO, unsigned int programID, unsigned int textureID , unsigned int projectionLoc, float *projectionMat, Mat3 &matrix, float a_width, float a_height, int rotatePoint, Vec2 a_pivot) { //make sure we are drawing the current width of the object multiplied against the scale //otherwise changing the scale of the Mat3 isn't taken into account when drawing. float width = a_width * matrix.GetRightScale(); float height = a_height * matrix.GetUpScale(); Vec2 tl = Vec2(0, 0) + a_pivot; Vec2 tr = Vec2(width, 0) + a_pivot; Vec2 br = Vec2(0, height) + a_pivot; Vec2 bl = Vec2(width, height) + a_pivot; //set the 4 vert points to correct rotation tl = matrix.TransformPoint(tl); tr = matrix.TransformPoint(tr); br = matrix.TransformPoint(br); bl = matrix.TransformPoint(bl); Vertex vertexData[4] = { Vertex(tl.x, tl.y, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f), Vertex(tr.x, tr.y, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f), Vertex(bl.x, bl.y, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f), Vertex(br.x, br.y, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f) }; GLubyte indices[6] = { 0, 1, 2, // first triangle 0, 2, 3 // second triangle }; glUseProgram(programID); //std::cout << glGetError() << std::endl; // bind our texture to active texture 0... glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, textureID); int textureLocation = glGetUniformLocation(programID, "myTextureSampler"); glUniform1i(textureLocation , 1 ); //send our orthographic projection info to the shader glUniformMatrix4fv(projectionLoc, 1, GL_FALSE, projectionMat); glBindBuffer(GL_ARRAY_BUFFER, VBO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO); //allocate space for vertices on the graphics card glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex)*4, vertexData, GL_STREAM_DRAW); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLubyte)*6, indices, GL_STREAM_DRAW); //enable the vertex array state, since we're sending in an array of vertices glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glEnableVertexAttribArray(2); glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0); glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)16); glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)32); //glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(sizeof(float)*8)); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, NULL); // glDrawArrays(GL_QUADS, 0, 4); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindTexture(GL_TEXTURE_2D, 0); glUseProgram(0); //debug collision circles by displaying them //note that collision code should match this method for positions collision circles to be correct //create a posiiton around the world 0 point for the centre of the object to transform from // Vec2 drawPos = Vec2((width / 2) + a_pivot.x, (height / 2) + a_pivot.y); // // //transform the circle point to where it needs to go // drawPos = matrix.TransformPoint(drawPos); // // float radius = getRadius(width, height, matrix.GetRightScale()); // //draw the circle // DrawCircle(drawPos.x, drawPos.y, radius, 12, projectionLoc, projectionMat); // }