我无法在黑色窗口中看到我的三角形。窗口只是在打开时关闭,并且不允许我看到里面发生了什么。我在网上的某个地方看到我与次要版本控制有关,我不知道如何检查我的 VGA 卡。
这是我的完整代码:
#define GLEW_STATIC
#include <stdio.h>
#include <GL\glew.h>
#include <GL\GLU.h>
#include <GL\glut.h>
#include <glm.hpp>
#include <GL\gl.h>
#include <GLFW\glfw3.h>
using namespace glm;
using namespace std;
int main()
{
glfwWindowHint(GLFW_SAMPLES, 4); // anti aliasing
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // openGL major version to be 3
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); // minor set to 3, which makes the version 3.3
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // for MAC OS only
glfwWindowHint(GLFW_OPENGL_COMPAT_PROFILE, GLFW_OPENGL_CORE_PROFILE); //avoid using old openGL
GLFWwindow* window;
window = glfwCreateWindow(1024, 768, "First Window in OpenGL", NULL, NULL); …Run Code Online (Sandbox Code Playgroud) 假设我要在 GLFW 中设置回调函数
glfwSetCursorPosCallback(window, mouse);
Run Code Online (Sandbox Code Playgroud)
检索光标位置的最明显的方法是
vec2 m;
void mouse (GLFWwindow* window, GLdouble x, GLdouble y)
{
m = vec2 (x, y);
}
Run Code Online (Sandbox Code Playgroud)
但是,我更愿意在不使用全局变量的情况下这样做。能做到吗?
我有一个名为 renderLoop 的方法,它将处理我所有的绘图。当我运行程序时,我得到了这个异常。这个异常究竟是什么以及如何解决它?
当我从此类外部的函数回调(framebuffer_size_callback,调整窗口大小)调用 glViewport() 时,我也会遇到相同的异常。
#include "../Headers/glfwSetup.h"
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height);
}
void processInput(GLFWwindow* window)
{
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
{
glfwSetWindowShouldClose(window, true);
}
}
GlfwSetup::GlfwSetup()
{
LogStart("Constructor : glfwSetup");
Check(glfwInit(), "glfwInit() : [ GL_TRUE ]", "glfw Init() : [ GL_FALSE ]"); // init the glfw library
//manages function pointers for OpenGL so we want to initialize GLAD before we call any OpenGL functions
Check(!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress), "GLAD Initialized", "Failed To Initialize …Run Code Online (Sandbox Code Playgroud) 我正在做我的一个小项目,我基本上是在创建我自己的 C++ 游戏引擎/框架来创建图形和/或简单的游戏。我将 OpenGL 与 GLFW 一起使用。我的目标是拥有类似于各种图形框架的东西,比如 raylib 或 openFrameworks(但当然是精简了)
实际上到目前为止一切正常,但我无法弄清楚如何正确地将输入与窗口类分开,因为窗口句柄输入对我来说似乎相当笨重,只会使窗口类变得混乱。
这是对我的窗口类的快速过度简化。(我没有在键码中包含枚举类。)
#pragma once
#include "../extern/GLFW/glfw3.h"
#include <string>
class Window {
private:
GLFWwindow* mWindow;
int mWidth;
int mHeight;
std::string mTitle;
public:
Window();
~Window();
void createWindow(std::string title, int width, int height);
void mainLoop();
GLFWwindow* getWindow() const { return mWindow; }
// Input
private:
bool Window::getKeyStatus(KEY key) {
static void keyCallback(GLFWwindow* mWindow, int key, int scancode, int action, int mods);
bool isKeyDown(KEY key);
};
Run Code Online (Sandbox Code Playgroud)
这是实施加
#include "Window.h"
#include <iostream>
Window::Window() {}
Window::~Window() …Run Code Online (Sandbox Code Playgroud) 我有一个使用 glut 的小程序,我现在需要使用 glfw 的原因有很多。由于我从未使用过 glfw,所以我遇到了很多问题。主要的有以下功能:glutDisplayFunc,glutReshapeFunc,glutIdleFunc和glutMainLoop。我刚刚发现 glfw 中没有等效的功能。我应该如何修改我的程序?
我的程序是关于一个 3 维旋转的锥体
我有一个功能displaycone:
void displayCone(void){
// clear the drawing buffer.
glClear(GL_COLOR_BUFFER_BIT); //
// set matrix mode
glMatrixMode(GL_MODELVIEW);
// clear model view matrix
glLoadIdentity();
// multiply view matrix to current matrix
gluLookAt(3.0, 3.0, 3.0-4.5, 0.0, 0.0,-4.5,0,1,0);
// ******
glPushMatrix();
glTranslatef(0.0, 0.0, -4.5);
glBegin(GL_LINES);
glColor3f (1.0, 1.0, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(2.0, 0.0, 0.0);
glColor3f (1.0, 1.0, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 2.0, …Run Code Online (Sandbox Code Playgroud) 我使用 GLFW 和 GLEW;问题是默认情况下启用了 vsync,我该如何关闭它?
我正在尝试使用 GLFW 编写 OpenGL 应用程序。文件结构如下
-USG
-build
-include
-glfw-3.3
-src
-CMakeLists.txt
-main.cpp
-CMakeLists.txt
Run Code Online (Sandbox Code Playgroud)
USG文件中的CMake如下。
cmake_minimum_required(VERSION 3.0)
project(USG)
#--------------------------------------------------------------------
# Set GLFW variables
#--------------------------------------------------------------------
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
#--------------------------------------------------------------------
# Add subdirectories
#--------------------------------------------------------------------
add_subdirectory(include/glfw-3.3)
add_subdirectory(src)
Run Code Online (Sandbox Code Playgroud)
而src文件中的CMakeLists如下
add_executable(usg main.cpp)
set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL REQUIRED)
if (OPENGL_FOUND)
target_include_directories(usg PUBLIC ${OPENGL_INCLUDE_DIR})
target_link_libraries(usg ${OPENGL_gl_LIBRARY})
endif()
target_link_libraries(usg glfw)
Run Code Online (Sandbox Code Playgroud)
我在 build 文件夹中运行,cmake ../然后运行make。运行 cmake 会按预期运行。运行 make 构建 …
这段代码有什么原因吗:
int main(int argc, char* argv[])
{
Main::Init();
std::thread worker(Main::Mainloop);
worker.join();
Main::Free();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
应该与此处的代码不同:
int main(int argc, char* argv[])
{
Main::Init();
Main::Mainloop();
Main::Free();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
注意Main该类被定义为单例,这里是代码:
main.h
#pragma once
#ifndef MAIN_H
#define MAIN_H
#include "window.h"
#include "mainloop.h"
class Main ///Singleton
{
public:
Main(const Main&) = delete;
Main(Main&&) = delete;
Main& operator=(const Main&) = delete;
Main& operator=(Main&&) = delete;
private:
Main();
static Main& Get_Instance();
friend int main(int argc, char* argv[]);
static void Mainloop();
static void Init(); …Run Code Online (Sandbox Code Playgroud) 我在 Windows 上使用 openFrameworks,它使用 GLFW 和 GLEW,我在不同 GPU 品牌上的扩展可用性方面遇到问题。
基本上,如果我在 openGL 2 上运行我的程序,扩展是可用的。但是,如果我更改为 openGL 3.2 或更高版本,则所有扩展在 Nvida(在 * GTX1080 上测试)和 Intel (*UHD) 上都不可用,但在 AMD(*Vega Mobile GL/GH 和 RX 5700)上不可用。
这意味着无法使用 GL_ARB_texture_float,因此我的计算着色器无法按预期工作。
我正在使用 openGL 4.3,用于计算着色器支持和英特尔 GPU 支持。所有驱动程序都是最新的,所有 GPU 都支持 GL_ARB_texture_float。
此外,在 GLSL 上启用扩展没有任何作用。
这就是 openFrameworks 制作上下文的方式:
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, settings.glVersionMajor);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, settings.glVersionMinor);
if((settings.glVersionMajor==3 && settings.glVersionMinor>=2) || settings.glVersionMajor>=4)
{
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
}
if(settings.glVersionMajor>=3)
{
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
}
Run Code Online (Sandbox Code Playgroud)
不确定发生了什么,也不知道如何搜索这样的问题。欢迎任何指点!