我正在尝试实现glGenerateMipmap,所以我可以继续重新着色我渲染的多维数据集的每个级别,除了程序不会编译给出错误
'错误C3861:'glGenerateMipmap':找不到标识符'
我已经包含'#include'并且在标题内部似乎存在定义(虽然在IF语句中?见下文)所以我想知道是否有办法重新定义/定位它以便程序将编译或运行,如果没有,是否有另一种方法可以自动生成mipmap?
#ifdef GL_GLEXT_PROTOTYPES
...
...
GLAPI void APIENTRY glGenerateMipmap (GLenum);
...
#endif /* GL_GLEXT_PROTOTYPES */
Run Code Online (Sandbox Code Playgroud)
非常感谢,克里斯
我正在从HLSL切换到GLSL
在顶点缓冲区中定义顶点属性时,必须调用
glVertexAttribPointer( GLuint index,
GLint size,
GLenum type,
GLboolean normalized,
GLsizei stride,
const GLvoid * pointer);
Run Code Online (Sandbox Code Playgroud)
并传递一个索引.但是如何指定哪个索引映射到着色器中的哪个语义?
例如gl_Normal.如何指定gl_Normal在顶点着色器中使用时,我希望这是索引为1的通用顶点属性?
GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glEnableVertexAttribArray(0);
vbo.bind(GL_ARRAY_BUFFER);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glDisableVertexAttribArray(0);
ibo.bind(GL_ELEMENT_ARRAY_BUFFER); //where do I put this?
glBindVertexArray(0);
while (glfwGetWindowParam(GLFW_OPENED)) {
glClear(GL_COLOR_BUFFER_BIT);
glBindVertexArray(vao);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, 0);
glfwSwapBuffers();
}
Run Code Online (Sandbox Code Playgroud)
我理解VAO的方式是我创建一个vao句柄并像这样绑定它
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
Run Code Online (Sandbox Code Playgroud)
现在我可以用这三个命令填充VAO
vbo.bind(GL_ARRAY_BUFFER);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glDisableVertexAttribArray(0);
Run Code Online (Sandbox Code Playgroud)
我应该注意到我在这里使用了自己的vbo类.
然后我关闭了我的VAO
glBindVertexArray(0);
Run Code Online (Sandbox Code Playgroud)
然后我可以在renderloop中加载它
glBindVertexArray(vao);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, 0);
Run Code Online (Sandbox Code Playgroud)
但我没有得到任何输出.
现在我认为它与我的索引数组有关.(ibo)如何将VAO与IBO一起使用?
我正在迁移我们的图形,从使用旧的固定管道功能到使用可编程管道.我们最简单的模型只是空间中的点集合,每个点可以用不同的形状表示.其中一个是立方体.
我将我的代码基于OpenGL超级明星的立方体示例.
在这个例子中,立方体被放置在一些随机的位置,而我将在空间中有一个固定的点.我想知道是否有办法将该列表传递给我的着色器,以便在每个点绘制一个立方体vs循环遍历列表并每次调用glDrawElements.这是否值得麻烦(性能明智)?
PS我们仅限于OpenGL 3.3功能.
我正在尝试运行一个简单的 OpenGL 程序,但无法让它显示任何内容。我在 Mac 上使用 Swift,尽管我对 Windows 上的 OpenGL 拥有丰富的经验,但我对这两者都不熟悉。程序运行良好(没有 GL 错误或任何内容),但没有任何显示,直到我在 openGL 初始化结束时添加此内容:
var vao:GLuint=0;checkGlError();
glGenVertexArrays(1, &vao);checkGlError();
glBindVertexArray(vao);checkGlError();
Run Code Online (Sandbox Code Playgroud)
然后,一旦我调用 glGenVertexArrays(),它就会给出 GL_INVALID_OPERATION,但是文档没有提到这一点。
我担心我可能没有 GL3 上下文(实际上我更喜欢只有 GL1/2 上下文,但是 Swift 标头似乎缺少像 glBegin() 和 glColor3f() 这样的东西,所以我决定满足于GL3),所以我尝试手动请求一个:
required init?(coder: NSCoder) {
super.init(coder: coder);
let attribs=[NSOpenGLPFAOpenGLProfile,NSOpenGLProfileVersion3_2Core,0];
pixelFormat=NSOpenGLPixelFormat(attributes: UnsafePointer<NSOpenGLPixelFormatAttribute>(attribs));
openGLContext=NSOpenGLContext(format: pixelFormat, shareContext: nil);
openGLContext.view=self;
openGLContext.makeCurrentContext();
};
Run Code Online (Sandbox Code Playgroud)
然而,这似乎根本没有影响事情。
在我的着色器中,我喜欢使用这样的语法:
layout (location = 0) in vec3 aPos;
所以,我可以只使用索引0中glVertexAttribPointer和这样的,节省了努力glGetAttribLocation通话。我想对uniform价值观做同样的事情,但如果我这样做
layout (location = 2) uniform float offset;
Run Code Online (Sandbox Code Playgroud)
我的顶点着色器无法编译。有没有办法实现相同的行为而不使用glGetUniformLocation?
我的代码给了我这个错误:
在program.exe中的0x00007FFCF428A6CF (nvoglv64.dll)处抛出异常:0xC0000005:读取位置0x000001D6B603F000时发生访问冲突。
在 Visual Studio 的调试输出窗口中,我还看到未加载 nvoglv64.dll 文件的 pdb。
因为我已将此代码添加到我的 openGL 应用程序中:
data = stbi_load("src/pickaxe.png", &width, &height, &nrChannels, 0);
if (!data) {
std::cout << "swords image loaded incorrectly " << std::endl;
}
else {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
}
Run Code Online (Sandbox Code Playgroud)
是由于加载图像还是函数 GLTEXIMAGE_2D 引起的?这是我的完整代码:
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
// global variables
int p_WIDTH = 1280;
int p_HEIGHT = 960;
int succes;
char info[512];
// buffers
// shader sources
const …Run Code Online (Sandbox Code Playgroud) 我是OpenGL的新手,并且有一个简单的程序,我现在正在搞乱.
我遇到的问题是当我传递一个数组来表示点的颜色时,颜色最终变成黑色.如果我只是在片段着色器中明确定义颜色,它可以正常工作,如果我在VAO中切换数据的索引,则三角形将移动到作为颜色的点.
我尝试使用API跟踪并获得以下内容:
6872: message: major api error 1282: GL_INVALID_OPERATION error generated. <program> is not a program object, or <shader> is not a shader object.
6872 @0 glAttachShader(program = 1, shader = 1)
6872: warning: glGetError(glAttachShader) = GL_INVALID_OPERATION
6876: message: major api error 1282: GL_INVALID_OPERATION error generated. Handle does not refer to the expected type of object (GL_SHADER_OBJECT_ARB).
6876 @0 glDeleteShader(shader = 1)
6876: warning: glGetError(glDeleteShader) = GL_INVALID_OPERATION
6878: message: major api error 1282: GL_INVALID_OPERATION error generated. Handle does not …Run Code Online (Sandbox Code Playgroud) 我一直在尝试从两个不同的VBO切换到只有一个具有交错属性的VBO.我可以在C++中实现它,但在Scala中它证明是非常困难的.
这是我的实现:
class Mesh(positions: Array[Float], textureCoordinates: Array[Float], indices: Array[Int])
{
// Create VAO, VBO and a buffer for the indices
val vao: Int = glGenVertexArrays
val vbo: Int = glGenBuffers
val ibo: Int = glGenBuffers
setup
private def setup(): Unit =
{
val interleavedBuffer: FloatBuffer = prepareFloatBuffer(positions ++ textureCoordinates)
val indicesBuffer: IntBuffer = prepareIntBuffer(indices)
// One VAO to bind them all!
glBindVertexArray(vao)
glBindBuffer(GL_ARRAY_BUFFER, vbo)
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo)
// Fill buffers with data
glBufferData(GL_ARRAY_BUFFER, interleavedBuffer, GL_STATIC_DRAW)
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL_STATIC_DRAW)
// Set vertex …Run Code Online (Sandbox Code Playgroud) 我已经使用自己的迷你管道(使用 mipmap)成功地在几何体上显示纹理,但我决定不使用 mip-map,因为我的软件实际上不需要对细节级别进行任何更改。它是 2d 的并且使用像素艺术。细节不应该改变。我要补充一点,我正在尝试在纹理图集中循环纹理,并且禁用 mip 映射可能会有助于避免问题。
但是,不调用glGenerateMipmap会产生空白屏幕。调用它会产生正确的纹理。
是否还有另一个我必须调用的函数?
以下是我的纹理生成函数(我传递一个指向已创建的纹理 id 的指针。)
GLboolean GL_texture_load(Texture* texture_id, const char* const path, const GLboolean alpha, const GLint param_edge)
{
// load image
SDL_Surface* img = nullptr;
if (!(img = IMG_Load(path))) {
fprintf(stderr, "SDL_image could not be loaded %s, SDL_image Error: %s\n",
path, IMG_GetError());
return GL_FALSE;
}
glBindTexture(GL_TEXTURE_2D, *texture_id);
// image assignment
GLuint format = (alpha) ? GL_RGBA : GL_RGB;
glTexImage2D(GL_TEXTURE_2D, 0, format, img->w, img->h, 0, format, GL_UNSIGNED_BYTE, img->pixels);
glGenerateMipmap(GL_TEXTURE_2D); …Run Code Online (Sandbox Code Playgroud) 我是OpenGL的初学者,我编写了一个顶点着色器并执行其他操作,例如编译着色器.
顶点着色器:
in vec4 vPosition;
in vec4 vColor;
out vec4 Color;
void main(void){
gl_Position = vPosition;
Color = vColor;
}
Run Code Online (Sandbox Code Playgroud)
用C++编写这段代码之后:
GLuint PositionID = glGetAttribLocation(SProgram, "vPosition");
GLuint ColorID = glGetAttribLocation(SProgram, "vColor");
cout << "vPosition location: " << PositionID << endl << "vColor location: " << ColorID << endl;
Run Code Online (Sandbox Code Playgroud)
结果非常有趣,两个相同的位置:
vPosition location: 4294967295
vColor location: 4294967295
Run Code Online (Sandbox Code Playgroud)
那是什么原因?