我正在尝试使用 stb_image.h 加载图像,但在 gcc 提供的 <emmintrin.h> 版本中遇到两个编译器错误。我认为可能需要一个编译器选项,但我一直无法找到它是什么。
错误代码:
/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/include/emmintrin.h:1230:10: error: the last argument must be an 8-bit immediate
1230 | return (__m128i)__builtin_ia32_pslldqi128 (__A, __N * 8);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/include/emmintrin.h:1224:10: error: the last argument must be an 8-bit immediate
1224 | return (__m128i)__builtin_ia32_psrldqi128 (__A, __N * 8);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Run Code Online (Sandbox Code Playgroud)
<emmintrin.h> 中的相关代码:
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
_mm_srli_si128 (__m128i __A, const int __N)
{
return (__m128i)__builtin_ia32_psrldqi128 (__A, __N * 8);
}
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
_mm_slli_si128 (__m128i __A, const …Run Code Online (Sandbox Code Playgroud) 我正在使用 stb 库动态加载 OpenGL 纹理。我正在尝试使用 stb_image_write.h 中的函数。我找不到任何有关如何正确使用该函数的文档stbi_write_png_to_mem我的代码如下所示
#ifndef STB_IMAGE_WRITE_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include <stb/stb_image_write.h>
int main( )
{
// data is filled in later in program
int size , width , height ;
unsigned char* data = ( unsigned char* ) malloc( width * height ) ;
...
...
...
// this is where the issue lies
stbi_write_png_to_mem( ) ;
}
Run Code Online (Sandbox Code Playgroud)
我查看了 github 并浏览了源代码本身。我在谷歌上找不到任何东西。我不确定这个函数的输入需要什么,因为什么都不清楚是什么意思。该函数的源是
STBIWDEF unsigned char *stbi_write_png_to_mem(const unsigned char *pixels, int stride_bytes, int x, int y, int n, …Run Code Online (Sandbox Code Playgroud) 几天来我一直在尝试解决这个视觉错误,但没有成功,所以我问这个问题是为了看看是否有人可以帮助我理解发生了什么。
首先,我将在没有任何代码的情况下描述问题,然后我将提供一些代码。情况如下:
我的 OpenGL 应用程序将此图像渲染到多重采样帧缓冲区:
然后,我将该多重采样帧缓冲区传输到常规帧缓冲区(不是多重采样帧缓冲区)。
然后,我使用 将该常规帧缓冲区中的 RGB 数据读取到无符号字节数组中glReadPixels。
最后,我stbi_write_png使用无符号字节数组进行调用。这是结果:
对我来说,第一行字节被向右移动,这导致所有其他行被移动,从而形成对角线形状。
这是我的代码:
int width = 450;
int height = 450;
int numOfSamples = 1;
// Create the multisample framebuffer
glGenFramebuffers(1, &mMultisampleFBO);
glBindFramebuffer(GL_FRAMEBUFFER, mMultisampleFBO);
// Create a multisample texture and use it as a color attachment
glGenTextures(1, &mMultisampleTexture);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mMultisampleTexture);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, numOfSamples, GL_RGB, width, height, GL_TRUE);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, mMultisampleTexture, 0);
// Create a multisample renderbuffer object and use it as a depth …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 OpenGL 渲染纹理。我用作测试的纹理是一堆白色背景上的黑色矩形,如下所示:
但是,在渲染时,纹理似乎被复制并多次叠加在其自身之上:
我使用以下方法设置场景:
std::string vertexSource = ShaderLoader::load("vertexSource.vert");
const char* vsource = vertexSource.c_str();
std::string fragmentSource = ShaderLoader::load("fragmentSource.frag");
const char* fsource = fragmentSource.c_str();
int vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &vsource, NULL);
glCompileShader(vertexShader);
int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShader, 1, &fsource, NULL);
glCompileShader(fragmentShader);
shaderProgram = glCreateProgram();
glAttachShader(shaderProgram, vertexShader);
glAttachShader(shaderProgram, fragmentShader);
glLinkProgram(shaderProgram);
glDeleteShader(vertexShader);
glDeleteShader(fragmentShader);
float vertices[] = {
0.5f, 0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
-0.5f, -0.5f, 0.0f,
-0.5f, 0.5f, 0.0f,
1.0f, 1.0f,
1.0f, 0.0f,
0.0f, 0.0f,
0.0f, 1.0f,
};
unsigned int indices[] = …Run Code Online (Sandbox Code Playgroud) 我的代码给了我这个错误:
在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)