I am using glfw3 and glad library. The problem is that my cl.exe compiler isn't compiling the way I want it to .
Here is my main.cpp:
#define GLFW_INCLUDE_NONE
#include <iostream>
#include <Windows.h>
#include "C:\msvc64\include\GLFW\glfw3.h"
#include "C:\msvc64\include\GLFW\glfw3native.h"
#include "C:\msvc64\include\glad\gl.h"
void error_callback(int error, const char* description)
{
fprintf(stderr, "Error: %s\n", description);
}
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
// Key call backs.
}
void drawSquare() {
glColor3f(0.0, 1.0, 1.0);
glBegin(GL_POLYGON);
glVertex2f(0.5, 0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(-0.5, -0.5);
glVertex2f(0.5, -0.5);
glEnd();
}
int WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, PSTR cmdline, int cmdshow) {
if (!glfwInit())
{
return MessageBox(NULL, L"failed to initialize glfw", L"Error", 0);
};
glfwSetErrorCallback(error_callback);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(640, 480, "My Title", NULL, NULL);
if (!window)
{
glfwTerminate();
exit(EXIT_FAILURE);
return MessageBox(NULL, L"Failed to create window", L"Error", 0);
};
glfwSetKeyCallback(window, key_callback);
// Make the OpenGL context current
glfwMakeContextCurrent(window);
int width, height;
glfwGetFramebufferSize(window, &width, &height);
glViewport(0, 0, width, height);
double time = glfwGetTime();
while (!glfwWindowShouldClose(window)) {
// Main loop
glClear(GL_COLOR_BUFFER_BIT);
drawSquare();
glfwSwapBuffers(window);
glfwPollEvents();
// Check if the user attempted to close the window
if (glfwWindowShouldClose(window)) {
break; // Exit the loop
}
// Other application logic goes here
}
// Clean up and terminate GLFW
glfwTerminate();
return 0;
}
those libraries you see (msvc64) are libraries I made so that I can use cl.exe easier. I do not think the problem is with glfw3 since when I run the compilation with glfw3 only it compiles like a charm.
The command line code I used was:
CL.exe /c /IC:\msvc64\include\GLFW /IC:\msvc64\include\ /Zi /nologo /W3 /WX- /diagnostics:column /sdl /O2 /Oi /GL /D NDEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm- /EHsc /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /permissive- /Fo"C:\Users\name\Desktop\GameMake\\" /Fd"C:\Users\name\Desktop\GameMake\vc143.pdb" /external:W3 /Gd /TP /FC /errorReport:prompt main.cpp "C:\msvc64\src\gl.c"
main.cpp
gl.c
C:\msvc64\src\gl.c(2302,5): warning C4551: function call missing argument list.
I cant use the linking (link.exe) to convert this to .exe as I would need to use the .obj and other files created from cl.exe
link.exe /ERRORREPORT:PROMPT /OUT:"C:\Users\name\Desktop\GameMake\game.exe" /NOLOGO /LIBPATH:C:\msvc64\lib glfw3.lib OpenGL32.lib User32.lib gdi32.lib shell32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:\Users\name\Desktop\GameMake\game.pdb" /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /LTCG:incremental /LTCGOUT:"C:\Users\name\Desktop\GameMake\game.iobj" /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\Users\las-nawzad\Desktop\GameMake\game.lib"
/MACHINE:X64 C:\Users\las-nawzad\Desktop\GameMake\main.obj
I was expecting the code to compile without any difficulties and for me to convert the .cpp to an exe code.
I tried looking at the gl.c (from glad/src) and the line 2302 column 5 which I see GLAD_UNUSED(glad_gl_has_extension);
and I am stumped because I do not know why that line would be wrong. I also have tried downloading the glad library from https://gen.glad.sh/generated/tmpy5zlowskglad/ but I still get the same result.
I have solved the opengl problem. The problem was in the cl I should have also included the glad folder and KHR folder which was the problem then if you do that you will notice for the linking you would get an error thats because the cl would also make a glad.obj which you have to combine main.obj with glad.obj to make the working .exe
not only that you require gl.c, gl.h, glad.h and glad.c which can be downloaded from the glad generator. you would include gl.h (glad/include/gl.h) to the code and the compile it with glad.c (I dont know if gl.c and glad.h are necessary ).