public unsafe Window(string title, int width, int height, WindowFlags flags = WindowFlags.None) { Title = title; bool fullscreen = false; GLFWmonitor *monitor = null; if ((flags & WindowFlags.Fullscreen) != WindowFlags.None) { monitor = glfwGetPrimaryMonitor(); fullscreen = true; } if ((flags & WindowFlags.FullscreenDesktop) != WindowFlags.None) { monitor = glfwGetPrimaryMonitor(); //auto mode = glfwGetVideoMode(monitor); // //glfwWindowHint(GLFW_RED_BITS, mode->redBits); //glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits); //glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits); //glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate); glfwWindowHint(WindowHintBool.Decorated, false); fullscreen = true; } if (!fullscreen) { if ((flags & WindowFlags.Borderless) != WindowFlags.None) { glfwWindowHint(WindowHintBool.Decorated, false); } else { glfwWindowHint(WindowHintBool.Decorated, true); } if ((flags & WindowFlags.Resizable) != WindowFlags.None) { glfwWindowHint(WindowHintBool.Resizable, true); } if ((flags & WindowFlags.Hidden) != WindowFlags.None) { glfwWindowHint(WindowHintBool.Visible, false); } if ((flags & WindowFlags.Minimized) != WindowFlags.None) { glfwWindowHint(WindowHintBool.Iconified, true); } if ((flags & WindowFlags.Maximized) != WindowFlags.None) { glfwWindowHint(WindowHintBool.Maximized, true); } } _window = glfwCreateWindow(width, height, title, monitor, null); //Handle = hwnd; glfwGetWindowSize(_window, out width, out height); Extent = new VkExtent2D(width, height); }
//---------------------------------------------------------------------------------- // Main Entry point //---------------------------------------------------------------------------------- int main(void) { // Initialization //-------------------------------------------------------------------------------------- const int screenWidth = 800; const int screenHeight = 450; // GLFW3 Initialization + OpenGL 3.3 Context + Extensions //-------------------------------------------------------- glfwSetErrorCallback(ErrorCallback); if (!glfwInit()) { TraceLog(LOG_WARNING, "GLFW3: Can not initialize GLFW"); return(1); } else { TraceLog(LOG_INFO, "GLFW3: GLFW initialized successfully"); } glfwWindowHint(GLFW_SAMPLES, 4); glfwWindowHint(GLFW_DEPTH_BITS, 16); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); GLFWwindow *window = glfwCreateWindow(screenWidth, screenHeight, "rlgl standalone", NULL, NULL); if (!window) { glfwTerminate(); return(2); } else { TraceLog(LOG_INFO, "GLFW3: Window created successfully"); } glfwSetWindowPos(window, 200, 200); glfwSetKeyCallback(window, KeyCallback); glfwMakeContextCurrent(window); glfwSwapInterval(0); // Load OpenGL 3.3 supported extensions rlLoadExtensions(glfwGetProcAddress); //-------------------------------------------------------- // Initialize OpenGL context (states and resources) rlglInit(screenWidth, screenHeight); // Initialize viewport and internal projection/modelview matrices rlViewport(0, 0, screenWidth, screenHeight); rlMatrixMode(RL_PROJECTION); // Switch to PROJECTION matrix rlLoadIdentity(); // Reset current matrix (PROJECTION) rlOrtho(0, screenWidth, screenHeight, 0, 0.0f, 1.0f); // Orthographic projection with top-left corner at (0,0) rlMatrixMode(RL_MODELVIEW); // Switch back to MODELVIEW matrix rlLoadIdentity(); // Reset current matrix (MODELVIEW) rlClearColor(245, 245, 245, 255); // Define clear color rlEnableDepthTest(); // Enable DEPTH_TEST for 3D Camera camera = { 0 }; camera.position = (Vector3){ 5.0f, 5.0f, 5.0f }; // Camera position camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target) camera.fovy = 45.0f; // Camera field-of-view Y Vector3 cubePosition = { 0.0f, 0.0f, 0.0f }; // Cube default position (center) //-------------------------------------------------------------------------------------- // Main game loop while (!glfwWindowShouldClose(window)) { // Update //---------------------------------------------------------------------------------- //camera.position.x += 0.01f; //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- rlClearScreenBuffers(); // Clear current framebuffer // Draw '3D' elements in the scene //----------------------------------------------- // Calculate projection matrix (from perspective) and view matrix from camera look at Matrix matProj = MatrixPerspective(camera.fovy * DEG2RAD, (double)screenWidth / (double)screenHeight, 0.01, 1000.0); Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up); SetMatrixModelview(matView); // Set internal modelview matrix (default shader) SetMatrixProjection(matProj); // Set internal projection matrix (default shader) DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, RAYWHITE); DrawGrid(10, 1.0f); // NOTE: Internal buffers drawing (3D data) rlglDraw(); //----------------------------------------------- // Draw '2D' elements in the scene (GUI) //----------------------------------------------- #define RLGL_CREATE_MATRIX_MANUALLY #if defined(RLGL_CREATE_MATRIX_MANUALLY) matProj = MatrixOrtho(0.0, screenWidth, screenHeight, 0.0, 0.0, 1.0); matView = MatrixIdentity(); SetMatrixModelview(matView); // Set internal modelview matrix (default shader) SetMatrixProjection(matProj); // Set internal projection matrix (default shader) #else // Let rlgl generate and multiply matrix internally rlMatrixMode(RL_PROJECTION); // Enable internal projection matrix rlLoadIdentity(); // Reset internal projection matrix rlOrtho(0.0, screenWidth, screenHeight, 0.0, 0.0, 1.0); // Recalculate internal projection matrix rlMatrixMode(RL_MODELVIEW); // Enable internal modelview matrix rlLoadIdentity(); // Reset internal modelview matrix #endif DrawRectangleV((Vector2){ 10.0f, 10.0f }, (Vector2){ 780.0f, 20.0f }, DARKGRAY);