Mam zmienną:
std::vector<GLfloat> blackboard;
i funkcję która ładuje do tej zmiennej koordynaty figury:
Figures::Figures(std::string wayToFile)
{
int tmp = 0;
std::ifstream numbers(wayToFile);
if (!numbers)
{
std::cout << "Can't open file with blackboard";
getchar();
return;
}
while (!numbers.eof())
{
GLfloat temp;
numbers >> temp;
blackboard.push_back(temp);
}
numbers.close();
}
I nie wiem dlaczego nic nie chce się rysować. Gdy użyłem zwykłego amatorskiego kodu czyli wszystko w mainie to działało perfekcyjnie.
Jeżeli to pomoże to zamieszczam też maina
#include <GL/glew.h>
#include <glfw3.h>
#include <glm.hpp>
#include <gtc/matrix_transform.hpp>
#include <gtc/type_ptr.hpp>
#include <FreeImage.h>
#include <cmath>
#include <iostream>
#include <fstream>
#include <string>
#include "Rendering.h"
#include "Figures.h"
#include "Moving.h"
#include "setAndSend.h"
int main()
{
SetAndSend sas;
Rendering render;
Moving moving(800, 600, "", 4, true);
// Utworzenie obiektow VBO i VAO
Figures figureCube("C:/Game/Blocks/brick.txt");
Figures figureFloor("C:/Game/Blocks/floor.txt");
GLfloat tex_coords_floor[] = {
0.0f, 0.0f,
1.0f, 0.0f,
0.0f, 1.0f,
0.0f, 1.0f,
1.0f, 0.0f,
1.0f, 1.0f,
};
GLfloat tex_coords_cube[] = {
0.0f, 0.0f,
1.0f, 0.0f,
1.0f, 1.0f,
0.0f, 0.0f,
1.0f, 1.0f,
0.0f, 1.0f,
0.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,
0.0f, 1.0f,
1.0f, 0.0f,
1.0f, 1.0f,
1.0f, 0.0f,
0.0f, 0.0f,
0.0f, 1.0f,
1.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f,
1.0f, 0.0f,
0.0f, 0.0f,
1.0f, 1.0f,
1.0f, 1.0f,
0.0f, 0.0f,
0.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,
0.0f, 1.0f,
0.0f, 1.0f,
1.0f, 0.0f,
1.0f, 1.0f,
};
GLuint positionVbo1 = 0;
figureCube.setVbo(positionVbo1);
glBufferData(GL_ARRAY_BUFFER, sizeof(figureCube.blackboard.data()), figureCube.blackboard.data(), GL_STATIC_DRAW);
GLuint textureCoordsVbo1 = 0;
figureCube.setVbo(textureCoordsVbo1);
glBufferData(GL_ARRAY_BUFFER, sizeof(tex_coords_cube), tex_coords_cube, GL_STATIC_DRAW);
GLuint vao1 = 0;
figureCube.triangleWithTexture(vao1, positionVbo1, textureCoordsVbo1);
GLuint positionVbo2 = 0;
figureFloor.setVbo(positionVbo2);
glBufferData(GL_ARRAY_BUFFER, sizeof(figureFloor.blackboard.data()), figureFloor.blackboard.data(), GL_STATIC_DRAW);
GLuint texture_coords_vbo2 = 0;
figureFloor.setVbo(texture_coords_vbo2);
glBufferData(GL_ARRAY_BUFFER, sizeof(tex_coords_floor), tex_coords_floor, GL_STATIC_DRAW);
GLuint vao2 = 0;
figureFloor.triangleWithTexture(vao2, positionVbo2, texture_coords_vbo2);
GLuint shaders = render.loadShader("C:/Shaders/virtualCamera/vertexShader.glsl", "C:/Shaders/virtualCamera/fragmentShader.glsl");
glUseProgram(shaders);
GLint texture_slot = glGetUniformLocation(shaders, "basic_texture");
glUniform1i(texture_slot, 0);
GLint viewUniform = glGetUniformLocation(shaders, "view_matrix");
GLint perspectiveUniform = glGetUniformLocation(shaders, "perspective_matrix");
glActiveTexture(GL_TEXTURE0);
render.loadTexture("C:/Shaders/virtualCamera/Brick.jpg");
glActiveTexture(GL_TEXTURE1);
render.loadTexture("C:/Shaders/virtualCamera/Grass.jpg");
sas.setCamera(moving, viewUniform, perspectiveUniform);
render.deep();
while (!glfwWindowShouldClose(moving.window))
{
moving.previous_time = moving.actual_time;
moving.actual_time = glfwGetTime();
render.ClearColor(0.5, 0.5, 0.5, moving.window_width, moving.window_height);
// Wyslanie perspektywy i kamery do programu shadera
glUniformMatrix4fv(viewUniform, 1, GL_FALSE, glm::value_ptr(moving.view_matrix));
glUniformMatrix4fv(perspectiveUniform, 1, GL_FALSE, glm::value_ptr(moving.perspective));
// Rysowanie
glUniform1i(texture_slot, 0);
glBindVertexArray(vao1);
glDrawArrays(GL_TRIANGLES, 0, 30);
glUniform1i(texture_slot, 1);
glBindVertexArray(vao2);
glDrawArrays(GL_TRIANGLES, 0, 6);
render.ProcessWindowEvents(moving.window);
}
render.Terminate(moving.window);
return 0;
}