我正在从本教程学习OpenGL .我的问题是关于一般的规范,而不是关于特定的功能或主题.查看以下代码时:
glGenBuffers(1, &positionBufferObject);
glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertexPositions), vertexPositions, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
Run Code Online (Sandbox Code Playgroud)
我对在设置缓冲区数据之前和之后调用绑定函数的效用感到困惑.由于我对OpenGL和计算机图形学一般缺乏经验,这对我来说似乎是多余的.
手册页说:
glBindBuffer允许您创建或使用命名缓冲区对象.与目标设定为GL_ARRAY_BUFFER,GL_ELEMENT_ARRAY_BUFFER,GL_PIXEL_PACK_BUFFER或GL_PIXEL_UNPACK_BUFFER主叫glBindBuffer和缓冲设置为新的缓冲对象的名称绑定缓存对象名称的目标.当缓冲区对象绑定到目标时,该目标的先前绑定将自动中断.
将某些东西"绑定"到"目标"的概念/效用究竟是什么?
我的数据来自arduino(它从传感器获取数据)。
我想让用户程序处理数据(从 /dev/ttyUSB0 读取数据后)。
之后我需要使用程序的输出来控制鼠标光标。
(我真的很想避免此时编写内核驱动程序。)
推荐的方法是什么(在 Linux 环境中)?
也许是 X 之上的库...或者我可以直接将数据通过管道传输到的一些工具/脚本?
问题是,着色器(非常简单的,因为我正在学习OpenGL)无法以看似随机的方式编译(并提供随机错误消息*).但是,相同的着色器在大约3或4次尝试后编译.这是代码:
Shader::Shader(GLenum Type,std::string filename)
{
shader_type = Type;
std::ifstream ifs(filename);
if(!ifs)
throw(std::runtime_error("File:"+filename+" not opened."));
std::ostringstream stream;
stream<<ifs.rdbuf();
const GLchar* data = stream.str().c_str();
handle = glCreateShader(shader_type);
glShaderSource(handle,1,static_cast<const GLchar**>(&data),0);
glCompileShader(handle);
int status;
glGetShaderiv(handle,GL_COMPILE_STATUS,&status);
if(status == GL_FALSE)
{
int loglength;
glGetShaderiv(handle,GL_INFO_LOG_LENGTH,&loglength);
auto data = new char[loglength];
glGetShaderInfoLog(handle,loglength,&loglength,data);
std::string strdata(data);
delete [] data;
throw(std::runtime_error(strdata));
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,着色器最后没有缺少换行符,在最后一个分号后面有一个额外的空格,并使用制表符而不是空格.(正如互联网上各种旧帖所示!).
#version 330
in vec2 Position;
uniform mat4 transform;
void main()
{
gl_Position = transform*vec4(Position,0.0f,1.0f);
}
Run Code Online (Sandbox Code Playgroud)
错误:
0(1) : error C0000: syntax error, unexpected $undefined …
Run Code Online (Sandbox Code Playgroud) 以下代码有效:
data MyList a = Atom a | Cons a (MyList a) deriving (Show)
getAtom (Atom a) = a
myFindMax :: (Ord a) => MyList a -> a
myFindMax (Cons x xs) = let restMax = myFindMax xs in
if x > restMax then x else restMax
myFindMax x = getAtom x
Run Code Online (Sandbox Code Playgroud)
但是当我写作
myFindMax (Atom x) = getAtom x
Run Code Online (Sandbox Code Playgroud)
在其他模式之前,我得到了错误
Couldn't match expected type ‘MyList a’ with actual type ‘a’
‘a’ is a rigid type variable bound by
the type …
Run Code Online (Sandbox Code Playgroud)