#include "Window.h"
#include "VAO.h"
#include "ShaderProgram.h"
#include "Texture.h"
#include <gtc/matrix_transform.hpp>
#include <gtc/type_ptr.hpp>
#include "ImGui/imgui.h"
#include "ImGui/imgui_impl_glfw.h"
#include "ImGui/imgui_impl_opengl3.h"
using namespace std;
using namespace glm;
int main()
{
Window window(800, 600, "X_Engine");
Vertex vert[] =
{
{vec3(-0.5f,-0.5f,1.0f), vec2(0.0f, 0.0f)},
{vec3(0.0f, 0.5f, 1.0f), vec2(1.0f, 0.0f)},
{vec3(0.5f,-0.5f, 1.0f), vec2(0.5f, 1.0f)},
};
GLuint indicies[] =
{
0,1,2
};
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
ImGui::StyleColorsDark();
ImGuiStyle& style = ImGui::GetStyle();
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
style.WindowRounding = 0.0f;
style.Colors[ImGuiCol_WindowBg].w = 1.0f;
}
ImGui_ImplGlfw_InitForOpenGL(window.getWindow(), true);
ImGui_ImplOpenGL3_Init("#version 130");
VAO vao(new vector<Vertex>(vert, end(vert)), new vector<GLuint>(indicies, end(indicies)));
shared_ptr<Shader> vs(new Shader("shaders/s_vertex.glvs", VERTEX_SHADER));
shared_ptr<Shader> fs(new Shader("shaders/s_fragment.glfs", FRAGMENT_SHADER));
ShaderProgram program(vs, fs);
Texture tex0("img/Toothless.jpg");
Texture tex1("img/Toothless.png");
mat4 view, projection;
view = translate(view, vec3(0.0f, 0.0f, -5.0f));
projection = perspective(radians(45.0f), 800.0f / 600.0f, 0.1f, 100.0f);
bool show_demo_window = true;
while (window.IsOpen())
{
glfwPollEvents();
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
if (show_demo_window)
ImGui::ShowDemoWindow(&show_demo_window);
ImGui::Render();
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
//RENDER
tex0.Use(0);
tex1.Use(1);
program.Use();
mat4 model;
model = translate(model, vec3(0.5f, 0.0f, 0.0f));
glUniformMatrix4fv(glGetUniformLocation(program.getProgramID(), "model"), 1, GL_FALSE, glm::value_ptr(model));
glUniformMatrix4fv(glGetUniformLocation(program.getProgramID(), "view"), 1, GL_FALSE, glm::value_ptr(view));
glUniformMatrix4fv(glGetUniformLocation(program.getProgramID(), "projection"), 1, GL_FALSE, glm::value_ptr(projection));
program.setColor(vec4(1.0f, 0.0f, 0.0f, 1.0f));
vao.Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
GLFWwindow* backup_current_context = glfwGetCurrentContext();
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
glfwMakeContextCurrent(backup_current_context);
}
glfwSwapBuffers(window.getWindow());
}
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
return 0;
}
#version 330 core
layout (location=0) in vec3 position;
layout (location=1) in vec2 inTexCoord;
out vec2 TexCoord;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main()
{
gl_Position = projection*view*model*vec4( position.x, position.y, position.z, 1.0 );
TexCoord = inTexCoord;
}
#version 330 core
in vec2 TexCoord;
out vec4 color;
uniform sampler2D ourTex0;
uniform sampler2D ourTex1;
uniform vec4 uniformColor;
void main()
{
color = uniformColor * mix(texture(ourTex0, TexCoord), texture(ourTex1, TexCoord), 0.0);
}
witam otóż od niedawna zacząłem się uczyć opengl-a i jeszcze nie wiem jak on do końca działa ani jak działają te całe shader-y
problem głównie tkwi w tym że kiedy kompiluje kod i w moim vertexShaderz-e jest napisane : gl_Position = projection*view*model*vec4( position.x, position.y, position.z, 1.0 );
to okno wgl. nie wyświetla mi trójkąta zaś kiedy jest napisane tak: gl_Position = vec4( position.x, position.y, position.z, 1.0 ); to trójkąt już jest wyświetlany.
Proszę o pomoc daje kod do main-a i obu shader-ów jakby były potrzebne jeszcze jakieś inne pliki to wyślę.