我正在开发一个使用 GLFW 和 OpenGL 的 OpenGL 项目,但是我无法成功地将 GLFW 包含在我的项目中。
我使用的是 Linux Mint,并且使用通过终端编译的 C 代码clang version 10.0.0-4ubuntu1。IDE 是 Visual Studio Code。
代码:
#include "gui/window.h"
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
glfwSetWindowShouldClose(window, GLFW_TRUE);
}
}
int windowMain() {
// Initialize GLFW
if (!glfwInit()) {
fprintf(stderr, "Failed to initialize GLFW\n");
return -1;
}
// Create a window and OpenGL context
GLFWwindow* window = glfwCreateWindow(800, 600, "Basic …Run Code Online (Sandbox Code Playgroud) 我安装了GLFW 3(包括将文件夹包含到VS\C\include,lib到VS\C\lib和dll到SySWOW54).现在,当我尝试从文档中编译第一个示例时
#include <GLFW/glfw3.h>
#include <stdlib.h>
#include <stdio.h>
static void error_callback(int error, const char* description)
{
fputs(description, stderr);
}
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GL_TRUE);
}
int main(void)
{
GLFWwindow* window;
glfwSetErrorCallback(error_callback);
if (!glfwInit())
exit(EXIT_FAILURE);
window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL);
if (!window)
{
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window);
glfwSetKeyCallback(window, key_callback);
while (!glfwWindowShouldClose(window))
{
float ratio;
int width, height;
glfwGetFramebufferSize(window, &width, &height); …Run Code Online (Sandbox Code Playgroud) 我正在使用GLFW并创建一个GLFWwindow,它在它的标题"glfw3.h"中声明如下:
typedef struct GLFWwindow GLFWwindow;
通常,在堆上初始化结构时,我会执行以下操作:
GLFWwindow *window = new GLFWwindow();
Run Code Online (Sandbox Code Playgroud)
这给了我以下错误:无效使用不完整类型'GLFWwindow {aka struct GLFWwindow}','GLFWwindow {aka struct GLFWwindow}'的前向声明
这是我对该问题的修复:
GLFWwindow **window = new GLFWwindow*();
这个修复实际上有效,但我不明白为什么我需要它.
Thx提前
我正在尝试在OpenGL中渲染一些对象,但即使我glDrawElements用正确的模式调用它,它仍然给了我一个GL_INVALID_ENUM.这是AMD的CodeXL记录的呼叫记录,从设置到渲染:
glBindVertexArray(1)
... creating shaders/programs and getting uniform locations ...
# the vertex buffer
glGenBuffers(1, 0x008A945C)
glBindBuffer(GL_ARRAY_BUFFER, 1)
glBufferData(GL_ARRAY_BUFFER, 96, 0x008A94A0, GL_STATIC_DRAW)
# the element index buffer
glGenBuffers(1, 0x008A9460)
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 2)
glBufferData(GL_ELEMENT_ARRAY_BUFFER, 96, 0x008A9508, GL_STATIC_DRAW)
glClearColor(0.12, 0.63999999, 0.55000001, 1)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glEnableVertexAttribArray(0)
glUseProgram(1)
glUniformMatrix4fv(0, 1, FALSE, ... MVP Matrix ...)
glBindBuffer(GL_ARRAY_BUFFER, 1)
glVertexAttribPointer(0, 3, GL_FLOAT, FALSE, 0, 0x00000000)
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 2)
glDrawElements(GL_QUADS, 24, GL_UNSIGNED_INT, 0x00000000) # GL_INVALID_ENUM here <----
glUseProgram(0)
glDisableVertexAttribArray(0)
wglSwapBuffers(0x09011214)
Run Code Online (Sandbox Code Playgroud)
我已经尝试换glDrawElements用glDrawArrays(GL_QUADS, …
我正在尝试使用向量作为成员字段来设置对象。我设置了构造函数,据我所知它确实初始化了这个成员变量,但是当我尝试访问向量时出现错误,除非我在对象的函数调用中初始化它。我收到一条警告说
C26495: Variable 'Engy::Graphics::Shape2D::m_vertices' is uninitialized. Always initialize a member variable (type.6).
问题是,我确实在我的构造函数中初始化了它。我缺少什么重要的东西吗?这是我的代码:
类声明(头文件)
class Shape2D:Object
{
protected:
std::vector<Vector> *m_vertices;
int type = GL_QUADS;
public:
Shape2D(std::vector<Vector> vertices);
Shape2D();
void draw();
void setVector(int index, Vector value);
Vector getVector(int index);
void translate(double x, double y);
void createVector(int i, double x, double y);
void createVector(double x, double y);
void addVector(Vector value);
};
Run Code Online (Sandbox Code Playgroud)
方法声明(.cpp 文件)
Shape2D::Shape2D(std::vector<Vector> vertices)
{
std::vector<Vector> m_vertices = vertices;
}
Shape2D::Shape2D()
{
std::vector<Vector> *m_vertices = new std::vector<Vector>;
}
void Shape2D::setVector(int index, …Run Code Online (Sandbox Code Playgroud)