我正在使用Haskell和OpenGL.OpenGL有一种使用一组统一函数加载变量的方法:
glUniform1i location intValue
glUniform1f location floatValue
glUniform2i location intValue1 intValue2
... etc.
Run Code Online (Sandbox Code Playgroud)
我试图将其翻译成更惯用的Haskell.我想写一个函数:
uniform :: String -> a -> IO ()
uniform location value = ...
Run Code Online (Sandbox Code Playgroud)
我的问题是我调用的函数依赖于的值a.有没有办法做到这一点,而无需编写ň不同的功能?
我正在开发一款3D游戏,但已经进行了首次测试之一,只有很少的计算,我得到3或4 fps左右.以下是我的完整代码:http://pastebin.com/j2DWPS6Z 这是我在主代码中使用的Terrain.cpp文件:http://pastebin.com/d1gnE5KH
看看我用于绘图的代码,我只绘制了400个多边形.据我所知,不应该将fps降低到3到4 fps左右.
我使用的计算机是HP Elitebook 8570w,8GB内存和Intel内核i7,所以这不是问题所在.
有谁知道我做错了导致fps这么低?
我编写了这段代码,将纹理应用于以ply格式提供的bunny模型.兔子用纹理绘制,但不像看起来像毛皮,纹理看起来像粗点.
void GLRenderer::paintGL()
{
// Set light
GLfloat light_position[] = { lightPositionX, lightPositionY, lightPositionZ, 0.0 };
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Enabling texture
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
bindTexture(QImage("fur4.bmp"));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glEnable(GL_NORMALIZE);
glLoadIdentity();
glBegin(GL_TRIANGLES);
for( int i = 0 ; i < objPLYParser.g_vpX.size() ; i+=3 )
{
float vector1[3], vector2[3], vCross[3], normalizationValue;
vector1[0] = objPLYParser.g_vpX[i] - objPLYParser.g_vpX[i+1];
vector1[1] = objPLYParser.g_vpY[i] - objPLYParser.g_vpY[i+1];
vector1[2] = objPLYParser.g_vpZ[i] - objPLYParser.g_vpZ[i+1];
vector2[0] = objPLYParser.g_vpX[i] …Run Code Online (Sandbox Code Playgroud) 我最近发现有一个名为"Assimp"的库用于导入可以在c ++ opengl中渲染动画的模型,现在我试着弄清楚我要做什么,以便加载纹理模型并绘制它...
1)建议从Blender导出动画的格式是什么?
2)我已经有了一个基本的网格类,绘制了一个模型.我需要修改什么来支持动画?
我的数据结构:
struct ObjectData {
vector <glm::vec3> vertices, normals, colors;
vector <glm::vec2> texCoords;
vector <GLuint> vIndices, uIndices, nIndices;
vector <Material*> materials;
glm::vec3 size, center;
};
Run Code Online (Sandbox Code Playgroud)
我的网格VBO和绘制:
void Mesh::draw() {
if (initialized) {
shader->enable(true);
if (texture != NULL) {
texture->enable(true);
}
//Tell OpenGL which array to use
glBindVertexArray(arrayObject);
glDrawElements(renderMode, object->vIndices.size(), GL_UNSIGNED_INT, 0);
glBindVertexArray(NULL);
shader->enable(false);
if (texture != NULL) {
texture->enable(false);
}
}
}
void Mesh::updateVBO() {
if (!initialized) {
glGenVertexArrays(1, &arrayObject);
}
//Tell OpenGL which vertex array …Run Code Online (Sandbox Code Playgroud) 如果Opengl允许创建width = height = 0的纹理,那么指定其他参数(例如内部格式,格式等)的用途是什么。其次,这种纹理的用途是什么。
所以Oculus Rift SDK接受使用glFramebufferTexture函数创建的帧缓冲纹理ID .
例:
[...]
GLuint l_FBOId;
glGenFramebuffers(1, &l_FBOId);
glBindFramebuffer(GL_FRAMEBUFFER, l_FBOId);
// The texture we're going to render to...
GLuint l_TextureId;
glGenTextures(1, &l_TextureId);
// "Bind" the newly created texture : all future texture functions will modify this texture...
glBindTexture(GL_TEXTURE_2D, l_TextureId);
// Give an empty image to OpenGL (the last "0")
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, l_TextureSize.w, l_TextureSize.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
// Linear filtering...
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// Create Depth Buffer...
GLuint l_DepthBufferId;
glGenRenderbuffers(1, &l_DepthBufferId);
glBindRenderbuffer(GL_RENDERBUFFER, …Run Code Online (Sandbox Code Playgroud) 我正在使用C++中的GLUT创建一个3D应用程序.
现在,我想实现一个类似于此的方法:
Vector3* MyClass::get3DObjectfromMouse(int mouseX, int mouseY);
我该如何实现这个方法?
所以我一直想知道如何在lwjgl中更改openGL版本..我知道我可以用维基上的PixelFormat和ContextAttribs更改版本 http://lwjgl.org/wiki/index.php?title=Version_selection
但是如果我想把它降到更低的话,那只能把我降到最低3.2?喜欢2.1甚至1.1?有没有办法做到这一点?
我可以使用FBO blitting https://www.opengl.org/registry/specs/EXT/framebuffer_blit.txt,将渲染的FBO作为纹理传递给我的解析着色器输入吗?
我可以使用FBO作为着色器"sampler2D"的输入吗?
我的意思是,我为fbo渲染了一些东西.现在我想要后处理图像,我可以将FBO作为纹理传递到着色器吗?
我正在尝试在OpenGL上学习本教程,而不是加载原始图像我正在使用lodePNG.
问题是,当我使用函数glTexImage2D时,我在最后一个参数上得到一个错误,它只需要一个GLvoid*变量.LodePNG仅输出std :: vector作为最终图像数据.我在这个问题上找不到任何其他资源.
我如何才能使这个功能起作用?该错误只是表明它不采用这种数据类型.