我现在正在编写使用OpenGL,Cg和C++实现直接光线投射体绘制.我的计算机系统是Win7,我的图形是nVidia GTX570.
实际上,我已经成功实现了直接光线投射体积渲染的基本功能.但是现在我想在它上面添加照明并使用局部照明模型.在我添加几行代码进行照明之后,我得到了Cg编译器错误.在添加之前,它运行良好.
我使用的Cg配置文件是CG_PROFILE_VP40和CG_PROFILE_FP40.
现在我发布我的Cg代码:
#define kNumberOfRaySteps 800
// Define interface between the application and the vertex program
struct app_vertex
{
float4 Position : POSITION;
float4 TexCoord : TEXCOORD1;
float4 Color : COLOR0;
};
// Define the interface between the vertex- and the fragment programs
struct vertex_fragment
{
float4 Position : POSITION; // For the rasterizer
float4 TexCoord : TEXCOORD0;
float4 Color : TEXCOORD1;
float4 Pos : TEXCOORD2;
};
struct fragment_out …Run Code Online (Sandbox Code Playgroud) 我现在正尝试使用C++,OpenGL和GLSL(用于GPU加速)实现Ray Casting Volume Rendering.为了获得更好的质量和性能,我想使用八叉树来组织3D医疗体积数据,因此我可以轻松地使用空间跳跃和自适应采样等算法.
但是如何有效地构建八叉树呢?如何访问八叉树?当光线在体数据中传播时,如何确定样本点所属的八叉树的哪个单元格或叶子?
看看下面的OpenGL函数:
void glTexImage2D(GLenum target,
GLint level,
GLint internalFormat,
GLsizei width,
GLsizei height,
GLint border,
GLenum format,
GLenum type,
const GLvoid * data);
Run Code Online (Sandbox Code Playgroud)
我知道参数格式和类型描述了图像数据的格式和类型,但是我不了解参数internalFormat.我应该如何在我的应用程序中设置它的值?
例如,我创建一个这样的纹理:
glTexImage2D(GL_TEXTURE_2D,0,GL_LUMINANCE8,size,size,0,GL_LUMINANCE,GL_UNSIGNED_BYTE,buffer);
Run Code Online (Sandbox Code Playgroud)
当我在我的GLSL着色器中使用它的纹理时,我得到的值似乎在[0,1] .WHy之间?它不应该在[0,255]之间吗?
我的着色器代码的一部分是:
vec = EntryPoint + delta_dir * texture(noiseTex,EntryPoint.xy * 32).x;
Run Code Online (Sandbox Code Playgroud)
我的C++代码的一部分:
for (int i = 0;i < temp;++i)
{
buffer[i] = 255.0 * rand() / (float)RAND_MAX;
}
glGenTextures(1,&noiseTex);
glActiveTexture(GL_TEXTURE0 + activeTexUnit);
glBindTexture(GL_TEXTURE_2D,noiseTex);
glTexImage2D(GL_TEXTURE_2D,0,GL_LUMINANCE8,size,size,
0,GL_LUMINANCE,GL_UNSIGNED_BYTE,buffer);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
Run Code Online (Sandbox Code Playgroud) 我想实现以下内容:
我定义了一个函数.当我在函数后写N 时(),函数将被调用N次.
我举个例子:
#include <iostream>
using namespace std;
typedef void* (*c)();
typedef c (*b)();
typedef b (*a)();
a aaa()
{
cout<<"Google"<<endl;
return (a)aaa;
}
int main()
{
aaa()()()();
system("pause");
}
Run Code Online (Sandbox Code Playgroud)
然后输出是:

还有其他方法可以实现吗?
我写了一个程序来绘制一个简单的三角形,我使用VAO,VBO和GLSL着色器.结果如下:

但如果我使用以下方法启用深度测试
glEnable(GL_DEPTH_TEST)
Run Code Online (Sandbox Code Playgroud)
窗口中没有任何内容.
现在我发布一些我的程序代码:
float positionData[] = {
-0.8f, -0.8f, 0.0f,
0.8f, -0.8f, 0.0f,
0.0f, 0.8f, 0.0f };
float colorData[] = {
1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 1.0f };
void initVBO()
{
// Create and populate the buffer objects
GLuint vboHandles[2];
glGenBuffers(2, vboHandles);
GLuint positionBufferHandle = vboHandles[0];
GLuint colorBufferHandle = vboHandles[1];
glBindBuffer(GL_ARRAY_BUFFER,positionBufferHandle);
glBufferData(GL_ARRAY_BUFFER,9 * sizeof(float),
positionData,GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER,colorBufferHandle);
glBufferData(GL_ARRAY_BUFFER,9 * sizeof(float),
colorData,GL_STATIC_DRAW);
glGenVertexArrays(1,&vaoHandle);
glBindVertexArray(vaoHandle);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER, positionBufferHandle);
glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte *)NULL ); …Run Code Online (Sandbox Code Playgroud) 现在我在OpenGL中将六种不同的纹理应用于六个传真的立方体,但结果看起来并不正确.我从我的磁盘上加载了六张bmp图片,它们的大小都是256*256.我使用了SOIL(简单的OpenGL图像库:可以在这里下载:http://nehe.gamedev.net/tutorial/lesson_06_texturing_update/47002 /)加载bmp图片来构建纹理.
现在我在这里列出我的代码:
#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>
#include "SOIL.h"
GLuint texture[6];//6 textures for 6 faces of the cube
GLfloat xRot,yRot,zRot;//control cube's rotation
//load the bitmap and convert it into a texture
int LoadGLTextures()
{
int Status = 0;
char *bmpFile[6] = {"BmpFile/Ferrary.bmp","BmpFile/Honda.bmp","BmpFile/Hust.bmp",
"BmpFile/Lamborghini.bmp","BmpFile/NeHe.bmp","BmpFile/Porsche.bmp"};
for (int i = 0;i < 6;++i)
{
texture[i] = SOIL_load_OGL_texture(
bmpFile[i],
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_INVERT_Y);
printf("texture[%d]: %d\n",i,texture[i]);
if(texture[i] == 0)
Status = 0;
glBindTexture(GL_TEXTURE_2D,texture[i]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
}
return Status;
}
int …Run Code Online (Sandbox Code Playgroud)