我的测试程序的目标是擦除一个简单的字符串向量中的单元格,如下所示.程序失败(分段错误).
static void display(std::vector<std::string> const &vec)
{
std::vector<std::string>::const_iterator It = vec.begin();
for (; It != vec.end(); ++It)
std::cout << *It << " ";
std::cout << std::endl;
}
int main(void)
{
std::vector<std::string> vec;
size_t index = 0;
vec.push_back("Toto");
vec.push_back("Titi");
vec.push_back("Tata");
vec.push_back("Tutu");
display(vec);
std::vector<std::string>::iterator It = vec.begin();
for (size_t idx = 0; It != vec.end(); ++It, idx++)
if (!(*It).compare("Tutu"))
index = idx;
vec.erase(std::remove(vec.begin(), vec.end(), index), vec.end()); //Segmentation fault
display(vec);
getchar();
return (0);
}
Run Code Online (Sandbox Code Playgroud)
有人能帮帮我吗?在此先感谢您的帮助.
我的程序的目标是使用GLSL着色器渲染由光点照亮的简单立方体.问题是我的立方体保持黑色,就像禁用了照明属性一样.几个小时以来,我一直在寻找解决方案.我有两个缓冲区(一个用于位置顶点,另一个用于普通顶点).这两个缓冲区由Blender生成.我以前在使用Vertex Arrays的基本OpenGL程序中使用它们,它运行得很好.现在我只想做同样的事情,但这一次使用GLSL着色器.
这是我的C++代码的一部分:
static GLfloat LightPosition[4] = {0.0f, 10.0f, 10.0f, 1.0f};
static GLfloat Kd[3] = {0.9f, 0.5f, 0.3f};
static GLfloat Ld[3] = {1.0f, 1.0f, 1.0f};
[...]
tatic GLuint initShaders(char const *vertShaderSrc, char const *fragShaderSrc)
{
GLuint vertShaderID = 0, fragShaderID = 0;
compileShader(vertShaderID, GL_VERTEX_SHADER, vertShaderSrc);
compileShader(fragShaderID, GL_FRAGMENT_SHADER, fragShaderSrc);
GLuint programID = glCreateProgram();
glAttachShader(programID, vertShaderID);
glAttachShader(programID, fragShaderID);
glBindAttribLocation(programID, 0, "VertexPosition");
glBindAttribLocation(programID, 1, "VertexNormal");
glUniform3f(glGetUniformLocation(programID, "Kd"), Kd[0], Kd[1], Kd[2]);
glUniform3f(glGetUniformLocation(programID, "Ld"), Ld[0], Ld[1], Ld[2]);
glLinkProgram(programID);
GLint errorLink = 0;
glGetProgramiv(programID, GL_LINK_STATUS, &errorLink); …Run Code Online (Sandbox Code Playgroud) 对于我的程序,我需要无序密钥.为了完成工作,我使用std :: unordered_map容器.这是一个测试代码:
#include <iostream>
#include <unordered_map>
#include <string>
int main()
{
std::unordered_map<std::string, int> toto;
toto["Outlook"] = 454;
toto["Temperature"] = 4;
toto["Humidity"] = 554;
toto["Wind"] = 545454;
std::unordered_map<std::string, int>::iterator It = toto.begin();
std::cout << toto.size() << std::endl;
for (; It != toto.end(); ++It)
std::cout << (*It).first << std::endl;
getchar();
return (0);
}
Run Code Online (Sandbox Code Playgroud)
在Windows(Visual Studio 2012)上,输出为:
Outlook
Temperature
Humidity
Wind
Run Code Online (Sandbox Code Playgroud)
这是正确的.没有应用排序.
但在Linux上输出如下:
Humidity
Outlook
Wind
Temperature
Run Code Online (Sandbox Code Playgroud)
PS:在linux上我使用-std :: c ++ 0x和-std = gnu ++ 0x编译我的程序,并且没有编译错误.
那么,如何在同一个程序中使用不同的行为呢?在此先感谢您的帮助 !
我正在使用Oriented-Hemisphere渲染技术研究SSAO(屏幕空间环境遮挡)算法.
I)算法
该算法需要输入:
这是我使用的片段着色器源代码:
#version 400
/*
** Output color value.
*/
layout (location = 0) out vec4 FragColor;
/*
** Vertex inputs.
*/
in VertexData_VS
{
vec2 TexCoords;
} VertexData_IN;
/*
** Inverse Projection Matrix.
*/
uniform mat4 ProjMatrix;
/*
** GBuffer samplers.
*/
uniform sampler2D PositionSampler;
uniform sampler2D NormalSampler;
/*
** Noise sampler.
*/
uniform sampler2D NoiseSampler;
/*
** Noise texture viewport.
*/
uniform vec2 NoiseTexOffset;
/* …Run Code Online (Sandbox Code Playgroud) 我的程序的目的是加载和显示每个面上具有相同纹理的简单立方体.但问题是输出不是很好(只有4个面被正确纹理化).我在纹理数组中尝试了很多坐标组合,但大多数情况下它更糟糕.是否可以使用glDrawElements函数正确设置纹理?
#define OFFSET_BUFFER(bytes) ((GLfloat *)NULL + bytes)
GLfloat vertices[] =
{
-1.0, -1.0, -1.0,
1.0, -1.0, -1.0,
1.0, 1.0, -1.0,
-1.0, 1.0, -1.0,
-1.0, -1.0, 1.0,
1.0, -1.0, 1.0,
1.0, 1.0, 1.0,
-1.0, 1.0, 1.0,
};
GLubyte indices[] =
{
0, 1, 2, 3,
4, 7, 6, 5,
0, 4, 5, 1,
3, 2, 6, 7,
0, 3, 7, 4,
1, 5, 6, 2
};
GLfloat textures[] =
{
0,0, 1,0, 1,1, 0,1,
0,1, 1,1, 1,0, 0,0,
/*//0,0, 1,0, 1,1, …Run Code Online (Sandbox Code Playgroud) 我不明白为什么下面的代码失败了:
char toto[54], titi[54]; //I already tried with allocations
sscanf_s(line, "%s-%s", &toto, &titi, sizeof(toto) + sizeof(titi));
Run Code Online (Sandbox Code Playgroud)
要么
sscanf_s(line, "%s-%s", &toto, &titi, sizeof(toto) + sizeof(titi));
Run Code Online (Sandbox Code Playgroud)
我的问题只有字符串(float,int,double等等),我使用Visual 2010.
有没有人有想法?非常感谢您的回答.
我只想知道如何将char(byte)中包含的十六进制值转换为整数.我想从.bmp文件转换颜色缓冲区,当然是十六进制文件并将其转换为整数.
例如 :
char rgb_hexa[3] = {0xA8, 0xF4, 0xD3};
Run Code Online (Sandbox Code Playgroud)
转换后:
int rgb_int[3] = {168, 244, 211};
Run Code Online (Sandbox Code Playgroud)
我总是尝试使用strtol,但它似乎只适用于char*.我试着做以下测试,但它不起作用:
char src_hexa_red = 0xA8;
char src_hexa_green = 0xF4;
char src_hexa_blue = 0xD3;
std::cout << "R=" << strtol(&src_hexa_red, (char**)NULL, 16) << ", G="
<< strtol(&src_hexa_green, (char**)NULL, 16) << ", B="
<< strtol(&src_hexa_blue, (char**)NULL, 16) << std::endl;
Run Code Online (Sandbox Code Playgroud)
有人能帮帮我吗?在此先感谢您的帮助.
我在哪里可以找到一个可以在Visual Studio上执行的程序来编译openGL源并生成像opengl32.lib,glut32.lib等库.实际上我有QT版本的问题.我想使用QT执行opengl但没有QT Opengl API.
这是错误消息:
lnk2026 module unsafe for safeseh image opengl32.lib
Run Code Online (Sandbox Code Playgroud)
我真的迷路了.在此先感谢您的帮助.