Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void drawBall(Shader ourShader) {
- // Build and compile our shader program
- // Shader ourShader("shader.vs", "shader.frag");
- GLuint VAO, VBO, EBO, VBO2;
- glGenVertexArrays(1, &VAO);
- glGenBuffers(1, &VBO);
- glGenBuffers(1, &EBO);
- glGenBuffers(1, &VBO2);
- // BIND VAO
- glBindVertexArray(VAO);
- // CREATE THE SPHERE
- //makeSphere();
- // ASSIGNING VBO AND EBO, POINTERS
- glBindBuffer(GL_ARRAY_BUFFER, VBO);
- glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(GLfloat), &vertices[0], GL_STATIC_DRAW);
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid*)0);
- glEnableVertexAttribArray(0);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(GLint), &indices[0], GL_STATIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER, VBO2);
- glBufferData(GL_ARRAY_BUFFER, UV.size() * sizeof(GLfloat), &UV[0], GL_STATIC_DRAW);
- glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid*)0);
- glEnableVertexAttribArray(2);
- // UNBIND VAO
- glBindVertexArray(0);
- glBindVertexArray(VAO);
- //glBindTexture(GL_TEXTURE_2D, texID);
- glActiveTexture(GL_TEXTURE0 + texID);
- //cout << "ball texture: " << texID << endl;
- GLint modelLoc = glGetUniformLocation(ourShader.Program, "model");
- //ACTUAL DRAWING
- loc = glGetUniformLocation(ourShader.Program, "ourTexture");
- glUniform1i(loc, texID);
- glm::mat4 model;
- model = glm::translate(model, ballPos);
- glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
- glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, 0);
- glBindVertexArray(0);
- // GETTING RID OF EVERYTHING BEFORE NEXT GAME LOOP
- glDeleteVertexArrays(1, &VAO);
- glDeleteBuffers(1, &VBO);
- glDeleteBuffers(1, &EBO);
- glDeleteBuffers(1, &VBO2);
- }
- GLuint texture1;
- void loadTexture() {
- glGenTextures(1, &texID);
- glActiveTexture(GL_TEXTURE0 + texID);
- glBindTexture(GL_TEXTURE_2D, texID);
- int text_w, text_h;
- unsigned char* image = SOIL_load_image(texturePath.c_str(), &text_w, &text_h, 0, SOIL_LOAD_RGB);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, text_w, text_h, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
- glGenerateMipmap(GL_TEXTURE_2D);
- SOIL_free_image_data(image);
- glBindTexture(GL_TEXTURE_2D, 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement