使用GLFW进行项目。出于某种原因,当我创建一个窗口而不是创建大小为640x480的窗口时,它制作了一个全屏窗口并将分辨率更改为所需的大小。知道我在做什么错吗?
Window(const std::string& name, int width = 0, int height = 0)
{
//We need to always initialize glfw before trying to create a window
glfwInit();
//Need to determine our monitor properties
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
const GLFWvidmode* desktopMode = glfwGetVideoMode(monitor);
//Initialize states that we want to define our window with
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_RESIZABLE, false);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RED_BITS, desktopMode->redBits);
glfwWindowHint(GLFW_GREEN_BITS, desktopMode->greenBits);
glfwWindowHint(GLFW_BLUE_BITS, desktopMode->blueBits);
glfwWindowHint(GLFW_REFRESH_RATE, desktopMode->refreshRate);
//Try to determine the size of the window
if (width <= 0 && height <= 0)
{
width = desktopMode->width;
height = desktopMode->height;
}
else
{
float aspectRatio = (float)desktopMode->height / (float)desktopMode->width;
if (width <= 0)
{
width = (int)roundf(height / aspectRatio);
}
if (height <= 0)
{
height = (int)roundf(width*aspectRatio);
}
}
//Actually create the window
window = glfwCreateWindow(width, height, name.data(), monitor, nullptr);
//Always focus the window upon creation
SetFocus();
}