diff --git a/OpenGL/Debug/Application.obj b/OpenGL/Debug/Application.obj new file mode 100644 index 0000000..5a160ee Binary files /dev/null and b/OpenGL/Debug/Application.obj differ diff --git a/OpenGL/Debug/OpenGL.exe.recipe b/OpenGL/Debug/OpenGL.exe.recipe new file mode 100644 index 0000000..a91c679 --- /dev/null +++ b/OpenGL/Debug/OpenGL.exe.recipe @@ -0,0 +1,11 @@ + + + + + D:\cpp\OpenGL\Debug\OpenGL.exe + + + + + + \ No newline at end of file diff --git a/OpenGL/Debug/OpenGL.ilk b/OpenGL/Debug/OpenGL.ilk new file mode 100644 index 0000000..70daa5d Binary files /dev/null and b/OpenGL/Debug/OpenGL.ilk differ diff --git a/OpenGL/Debug/OpenGL.log b/OpenGL/Debug/OpenGL.log new file mode 100644 index 0000000..65f511a --- /dev/null +++ b/OpenGL/Debug/OpenGL.log @@ -0,0 +1,5 @@ + Application.cpp +LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library +LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library +glew32s.lib(glew.obj) : warning LNK4099: PDB 'vc120.pdb' was not found with 'glew32s.lib(glew.obj)' or at 'D:\cpp\OpenGL\Debug\vc120.pdb'; linking object as if no debug info + OpenGL.vcxproj -> D:\cpp\OpenGL\Debug\OpenGL.exe diff --git a/OpenGL/Debug/OpenGL.tlog/CL.command.1.tlog b/OpenGL/Debug/OpenGL.tlog/CL.command.1.tlog new file mode 100644 index 0000000..96dc2fa Binary files /dev/null and b/OpenGL/Debug/OpenGL.tlog/CL.command.1.tlog differ diff --git a/OpenGL/Debug/OpenGL.tlog/CL.read.1.tlog b/OpenGL/Debug/OpenGL.tlog/CL.read.1.tlog new file mode 100644 index 0000000..88cd8fb Binary files /dev/null and b/OpenGL/Debug/OpenGL.tlog/CL.read.1.tlog differ diff --git a/OpenGL/Debug/OpenGL.tlog/CL.write.1.tlog b/OpenGL/Debug/OpenGL.tlog/CL.write.1.tlog new file mode 100644 index 0000000..b7dfd2e Binary files /dev/null and b/OpenGL/Debug/OpenGL.tlog/CL.write.1.tlog differ diff --git a/OpenGL/Debug/OpenGL.tlog/OpenGL.lastbuildstate b/OpenGL/Debug/OpenGL.tlog/OpenGL.lastbuildstate new file mode 100644 index 0000000..20f3372 --- /dev/null +++ b/OpenGL/Debug/OpenGL.tlog/OpenGL.lastbuildstate @@ -0,0 +1,2 @@ +PlatformToolSet=v143:VCToolArchitecture=Native32Bit:VCToolsVersion=14.31.31103:TargetPlatformVersion=10.0.19041.0: +Debug|Win32|D:\cpp\OpenGL\| diff --git a/OpenGL/Debug/OpenGL.tlog/link.command.1.tlog b/OpenGL/Debug/OpenGL.tlog/link.command.1.tlog new file mode 100644 index 0000000..765f912 Binary files /dev/null and b/OpenGL/Debug/OpenGL.tlog/link.command.1.tlog differ diff --git a/OpenGL/Debug/OpenGL.tlog/link.read.1.tlog b/OpenGL/Debug/OpenGL.tlog/link.read.1.tlog new file mode 100644 index 0000000..c161083 Binary files /dev/null and b/OpenGL/Debug/OpenGL.tlog/link.read.1.tlog differ diff --git a/OpenGL/Debug/OpenGL.tlog/link.write.1.tlog b/OpenGL/Debug/OpenGL.tlog/link.write.1.tlog new file mode 100644 index 0000000..c954736 Binary files /dev/null and b/OpenGL/Debug/OpenGL.tlog/link.write.1.tlog differ diff --git a/OpenGL/Debug/vc143.idb b/OpenGL/Debug/vc143.idb new file mode 100644 index 0000000..0b24eb3 Binary files /dev/null and b/OpenGL/Debug/vc143.idb differ diff --git a/OpenGL/Debug/vc143.pdb b/OpenGL/Debug/vc143.pdb new file mode 100644 index 0000000..75de98b Binary files /dev/null and b/OpenGL/Debug/vc143.pdb differ diff --git a/OpenGL/OpenGL.vcxproj b/OpenGL/OpenGL.vcxproj new file mode 100644 index 0000000..bcaa3ea --- /dev/null +++ b/OpenGL/OpenGL.vcxproj @@ -0,0 +1,162 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {79d31382-6947-4aaf-aea2-3838e3bdd2d4} + OpenGL + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + GLEW_STATIC;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + $(SolutionDir)Dependencies\GLFW\include;$(SolutionDir)Dependencies\GLEW\include + + + Console + true + $(SolutionDir)Dependencies\GLEW\lib\Release\Win32;$(SolutionDir)Dependencies\GLFW\lib-vc2022 + glew32s.lib;glfw3.lib;opengl32.lib;User32.lib;Gdi32.lib;Shell32.lib + + + + + Level3 + true + true + true + GLEW_STATIC;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + $(SolutionDir)Dependencies\GLFW\include;$(SolutionDir)Dependencies\GLEW\include + + + Console + true + true + true + $(SolutionDir)Dependencies\GLEW\lib\Release\Win32;$(SolutionDir)Dependencies\GLFW\lib-vc2022 + glew32s.lib;glfw3.lib;opengl32.lib;User32.lib;Gdi32.lib;Shell32.lib + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + $(SolutionDir)Dependencies\GLFW\include + + + Console + true + $(SolutionDir)Dependencies\GLFW\lib-vc2022 + glfw3.lib + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + $(SolutionDir)Dependencies\GLFW\include + + + Console + true + true + true + $(SolutionDir)Dependencies\GLFW\lib-vc2022 + glfw3.lib + + + + + + + + + + + + \ No newline at end of file diff --git a/OpenGL/OpenGL.vcxproj.filters b/OpenGL/OpenGL.vcxproj.filters new file mode 100644 index 0000000..706e1ae --- /dev/null +++ b/OpenGL/OpenGL.vcxproj.filters @@ -0,0 +1,25 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + + + + \ No newline at end of file diff --git a/OpenGL/OpenGL.vcxproj.user b/OpenGL/OpenGL.vcxproj.user new file mode 100644 index 0000000..966b4ff --- /dev/null +++ b/OpenGL/OpenGL.vcxproj.user @@ -0,0 +1,6 @@ + + + + true + + \ No newline at end of file diff --git a/OpenGL/res/shaders/Basic.shader b/OpenGL/res/shaders/Basic.shader new file mode 100644 index 0000000..3265b45 --- /dev/null +++ b/OpenGL/res/shaders/Basic.shader @@ -0,0 +1,19 @@ +#shader vertex +#version 330 core + +layout(location = 0) in vec4 position; + +void main() +{ + gl_Position = position; +}; + +#shader fragment +#version 330 core + +layout(location = 0) out vec4 color; + +void main() +{ + color = vec4(1, 1, 0, 1.0); +}; \ No newline at end of file diff --git a/OpenGL/src/Application.cpp b/OpenGL/src/Application.cpp new file mode 100644 index 0000000..477348e --- /dev/null +++ b/OpenGL/src/Application.cpp @@ -0,0 +1,180 @@ +#include +#include + +#include +#include +#include +#include + +struct ShaderProgramSource +{ + std::string VertexSource; + std::string FragmentSource; +}; + +static ShaderProgramSource ParseShader(const std::string& filePath) +{ + std::ifstream stream(filePath); + + enum class ShaderType + { + NONE = -1, VERTEX = 0, FRAGMENT = 1 + }; + + std::string line; + std::stringstream ss[2]; + ShaderType type = ShaderType::NONE; + while (getline(stream, line)) + { + if (line.find("#shader") != std::string::npos) + { + if (line.find("vertex") != std::string::npos) + type = ShaderType::VERTEX; + else if (line.find("fragment") != std::string::npos) + type = ShaderType::FRAGMENT; + } + else + { + ss[(int)type] << line << '\n'; + } + } + + return { ss[0].str(), ss[1].str() }; +} + +static int CompileShader(unsigned int type, const std::string& source) +{ + unsigned int id = glCreateShader(type); + const char* src = source.c_str(); + glShaderSource(id, 1, &src, nullptr); + glCompileShader(id); + + int result; + glGetShaderiv(id, GL_COMPILE_STATUS, &result); + + if (result == GL_FALSE) + { + int length; + glGetShaderiv(id, GL_INFO_LOG_LENGTH, &length); + char* message = (char*)alloca(length * sizeof(char)); + glGetShaderInfoLog(id, length, &length, message); + std::cout << "FAILED TO COMPILE " << (type == GL_VERTEX_SHADER ? "vertex" : "fragment") << "SHADER" << std::endl; + std::cout << message << std::endl; + glDeleteShader(id); + return 0; + } + + return id; +} + +static unsigned int CreateShader(const std::string& vertexShader, const std::string& fragmentShader) +{ + unsigned int program = glCreateProgram(); + unsigned int vs = CompileShader(GL_VERTEX_SHADER, vertexShader); + unsigned int fs = CompileShader(GL_FRAGMENT_SHADER, fragmentShader); + + glAttachShader(program, vs); + glAttachShader(program, fs); + glLinkProgram(program); + glValidateProgram(program); + + glDeleteShader(vs); + glDeleteShader(fs); + + return program; +} + +int main(void) +{ + /* Initialize the library */ + if (!glfwInit()) + return -1; + + /* Create a windowed mode window and its OpenGL context */ + GLFWwindow* window = glfwCreateWindow(640, 480, "Hello World", nullptr, nullptr); + + + if (!window) + { + glfwTerminate(); + return -1; + } + + /* Make the window's context current */ + glfwMakeContextCurrent(window); + + + if (glewInit() != GLEW_OK) + std::cout << "ERROR" << std::endl; + + std::cout << glGetString(GL_VERSION) << std::endl; + + constexpr float triforcePos[] = { + -1.0f, -1.0f, //0 + -0.5f, 0.0f, //1 -- + 0.0f, -1.0f, //2 + 0.0f, 1.0f, //3 + 0.5f, 0.0f, //4 -- + 1.0f, -1.0f //5 + + }; + + unsigned int triforceInd[] = { + 0, 1, 2, + 2, 4, 5, + 1, 3, 4 + + }; + + constexpr float positions[] = { + -0.5f, -0.5f, + 0.5f, -0.5f, + 0.5f, 0.5f, + -0.5f, 0.5f, + + }; + + unsigned int indices[] = { + 0, 1, 2, + 2, 3, 0 + }; + + unsigned int buffer; + glGenBuffers(1, &buffer); + glBindBuffer(GL_ARRAY_BUFFER, buffer); + glBufferData(GL_ARRAY_BUFFER, 6 * 2 * sizeof(float), triforcePos, GL_STATIC_DRAW); + + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0); + + unsigned int ibo; + glGenBuffers(1, &ibo); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, 3 * 3 * sizeof(unsigned int), triforceInd, GL_STATIC_DRAW); + + ShaderProgramSource source = ParseShader("res/shaders/Basic.shader"); + + unsigned int shader = CreateShader(source.VertexSource, source.FragmentSource); + glUseProgram(shader); + + /* Loop until the user closes the window */ + while (!glfwWindowShouldClose(window)) + { + /* Render here */ + glClear(GL_COLOR_BUFFER_BIT); + + glDrawElements(GL_TRIANGLES, 9, GL_UNSIGNED_INT, nullptr); + + + /* Swap front and back buffers */ + glfwSwapBuffers(window); + + /* Poll for and process events */ + glfwPollEvents(); + } + + glDeleteProgram(shader); + + glfwTerminate(); + return 0; +} \ No newline at end of file diff --git a/OpenGL/x64/Debug/Application.obj b/OpenGL/x64/Debug/Application.obj new file mode 100644 index 0000000..c44b2f3 Binary files /dev/null and b/OpenGL/x64/Debug/Application.obj differ diff --git a/OpenGL/x64/Debug/OpenGL.exe.recipe b/OpenGL/x64/Debug/OpenGL.exe.recipe new file mode 100644 index 0000000..a412c38 --- /dev/null +++ b/OpenGL/x64/Debug/OpenGL.exe.recipe @@ -0,0 +1,11 @@ + + + + + D:\cpp\OpenGL\x64\Debug\OpenGL.exe + + + + + + \ No newline at end of file diff --git a/OpenGL/x64/Debug/OpenGL.log b/OpenGL/x64/Debug/OpenGL.log new file mode 100644 index 0000000..b1024fc --- /dev/null +++ b/OpenGL/x64/Debug/OpenGL.log @@ -0,0 +1,11 @@ + Application.cpp +Application.obj : error LNK2019: unresolved external symbol __imp_glClear referenced in function main +Application.obj : error LNK2019: unresolved external symbol glfwInit referenced in function main +Application.obj : error LNK2019: unresolved external symbol glfwTerminate referenced in function main +Application.obj : error LNK2019: unresolved external symbol glfwCreateWindow referenced in function main +Application.obj : error LNK2019: unresolved external symbol glfwWindowShouldClose referenced in function main +Application.obj : error LNK2019: unresolved external symbol glfwPollEvents referenced in function main +Application.obj : error LNK2019: unresolved external symbol glfwMakeContextCurrent referenced in function main +Application.obj : error LNK2019: unresolved external symbol glfwSwapBuffers referenced in function main +D:\cpp\OpenGL\Dependencies\GLFW\lib-vc2022\glfw3.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64' +D:\cpp\OpenGL\x64\Debug\OpenGL.exe : fatal error LNK1120: 8 unresolved externals diff --git a/OpenGL/x64/Debug/OpenGL.tlog/CL.command.1.tlog b/OpenGL/x64/Debug/OpenGL.tlog/CL.command.1.tlog new file mode 100644 index 0000000..6397ae4 Binary files /dev/null and b/OpenGL/x64/Debug/OpenGL.tlog/CL.command.1.tlog differ diff --git a/OpenGL/x64/Debug/OpenGL.tlog/CL.read.1.tlog b/OpenGL/x64/Debug/OpenGL.tlog/CL.read.1.tlog new file mode 100644 index 0000000..2503585 Binary files /dev/null and b/OpenGL/x64/Debug/OpenGL.tlog/CL.read.1.tlog differ diff --git a/OpenGL/x64/Debug/OpenGL.tlog/CL.write.1.tlog b/OpenGL/x64/Debug/OpenGL.tlog/CL.write.1.tlog new file mode 100644 index 0000000..d840b76 Binary files /dev/null and b/OpenGL/x64/Debug/OpenGL.tlog/CL.write.1.tlog differ diff --git a/OpenGL/x64/Debug/OpenGL.tlog/OpenGL.lastbuildstate b/OpenGL/x64/Debug/OpenGL.tlog/OpenGL.lastbuildstate new file mode 100644 index 0000000..1992752 --- /dev/null +++ b/OpenGL/x64/Debug/OpenGL.tlog/OpenGL.lastbuildstate @@ -0,0 +1,2 @@ +PlatformToolSet=v143:VCToolArchitecture=Native64Bit:VCToolsVersion=14.31.31103:TargetPlatformVersion=10.0.19041.0: +Debug|x64|D:\cpp\OpenGL\| diff --git a/OpenGL/x64/Debug/OpenGL.tlog/link.32824-cvtres.read.1.tlog b/OpenGL/x64/Debug/OpenGL.tlog/link.32824-cvtres.read.1.tlog new file mode 100644 index 0000000..46b134b --- /dev/null +++ b/OpenGL/x64/Debug/OpenGL.tlog/link.32824-cvtres.read.1.tlog @@ -0,0 +1 @@ +ÿþ \ No newline at end of file diff --git a/OpenGL/x64/Debug/OpenGL.tlog/link.32824-cvtres.write.1.tlog b/OpenGL/x64/Debug/OpenGL.tlog/link.32824-cvtres.write.1.tlog new file mode 100644 index 0000000..46b134b --- /dev/null +++ b/OpenGL/x64/Debug/OpenGL.tlog/link.32824-cvtres.write.1.tlog @@ -0,0 +1 @@ +ÿþ \ No newline at end of file diff --git a/OpenGL/x64/Debug/OpenGL.tlog/link.32824-rc.read.1.tlog b/OpenGL/x64/Debug/OpenGL.tlog/link.32824-rc.read.1.tlog new file mode 100644 index 0000000..46b134b --- /dev/null +++ b/OpenGL/x64/Debug/OpenGL.tlog/link.32824-rc.read.1.tlog @@ -0,0 +1 @@ +ÿþ \ No newline at end of file diff --git a/OpenGL/x64/Debug/OpenGL.tlog/link.32824-rc.write.1.tlog b/OpenGL/x64/Debug/OpenGL.tlog/link.32824-rc.write.1.tlog new file mode 100644 index 0000000..46b134b --- /dev/null +++ b/OpenGL/x64/Debug/OpenGL.tlog/link.32824-rc.write.1.tlog @@ -0,0 +1 @@ +ÿþ \ No newline at end of file diff --git a/OpenGL/x64/Debug/OpenGL.tlog/link.32824.read.1.tlog b/OpenGL/x64/Debug/OpenGL.tlog/link.32824.read.1.tlog new file mode 100644 index 0000000..46b134b --- /dev/null +++ b/OpenGL/x64/Debug/OpenGL.tlog/link.32824.read.1.tlog @@ -0,0 +1 @@ +ÿþ \ No newline at end of file diff --git a/OpenGL/x64/Debug/OpenGL.tlog/link.32824.read.2.tlog b/OpenGL/x64/Debug/OpenGL.tlog/link.32824.read.2.tlog new file mode 100644 index 0000000..46b134b --- /dev/null +++ b/OpenGL/x64/Debug/OpenGL.tlog/link.32824.read.2.tlog @@ -0,0 +1 @@ +ÿþ \ No newline at end of file diff --git a/OpenGL/x64/Debug/OpenGL.tlog/link.32824.write.1.tlog b/OpenGL/x64/Debug/OpenGL.tlog/link.32824.write.1.tlog new file mode 100644 index 0000000..46b134b --- /dev/null +++ b/OpenGL/x64/Debug/OpenGL.tlog/link.32824.write.1.tlog @@ -0,0 +1 @@ +ÿþ \ No newline at end of file diff --git a/OpenGL/x64/Debug/OpenGL.tlog/link.command.1.tlog b/OpenGL/x64/Debug/OpenGL.tlog/link.command.1.tlog new file mode 100644 index 0000000..46b134b --- /dev/null +++ b/OpenGL/x64/Debug/OpenGL.tlog/link.command.1.tlog @@ -0,0 +1 @@ +ÿþ \ No newline at end of file diff --git a/OpenGL/x64/Debug/OpenGL.tlog/link.read.1.tlog b/OpenGL/x64/Debug/OpenGL.tlog/link.read.1.tlog new file mode 100644 index 0000000..46b134b --- /dev/null +++ b/OpenGL/x64/Debug/OpenGL.tlog/link.read.1.tlog @@ -0,0 +1 @@ +ÿþ \ No newline at end of file diff --git a/OpenGL/x64/Debug/OpenGL.tlog/link.write.1.tlog b/OpenGL/x64/Debug/OpenGL.tlog/link.write.1.tlog new file mode 100644 index 0000000..46b134b --- /dev/null +++ b/OpenGL/x64/Debug/OpenGL.tlog/link.write.1.tlog @@ -0,0 +1 @@ +ÿþ \ No newline at end of file diff --git a/OpenGL/x64/Debug/OpenGL.tlog/unsuccessfulbuild b/OpenGL/x64/Debug/OpenGL.tlog/unsuccessfulbuild new file mode 100644 index 0000000..e69de29 diff --git a/OpenGL/x64/Debug/vc143.idb b/OpenGL/x64/Debug/vc143.idb new file mode 100644 index 0000000..388ceaf Binary files /dev/null and b/OpenGL/x64/Debug/vc143.idb differ diff --git a/OpenGL/x64/Debug/vc143.pdb b/OpenGL/x64/Debug/vc143.pdb new file mode 100644 index 0000000..827040a Binary files /dev/null and b/OpenGL/x64/Debug/vc143.pdb differ