我试图在片段着色器中编写一个简单的光线追踪器。我有这个函数应该创建一个漫射球体,如下所示:
这是功能:
vec3 GetRayColor(Ray ray)
{
Ray new_ray = ray;
vec3 FinalColor = vec3(1.0f);
bool IntersectionFound = false;
int hit_times = 0;
for (int i = 0; i < RAY_BOUNCE_LIMIT; i++)
{
RayHitRecord ClosestSphere = IntersectSceneSpheres(new_ray, 0.001f, MAX_RAY_HIT_DISTANCE);
if (ClosestSphere.Hit == true)
{
// Get the final ray direction
vec3 R;
R.x = nextFloat(RNG_SEED, -1.0f, 1.0f);
R.y = nextFloat(RNG_SEED, -1.0f, 1.0f);
R.z = nextFloat(RNG_SEED, -1.0f, 1.0f);
vec3 S = normalize(ClosestSphere.Normal) + normalize(R);
S = normalize(S);
new_ray.Origin = ClosestSphere.Point;
new_ray.Direction = …Run Code Online (Sandbox Code Playgroud) 所以,我有一个程序使用图形模式[ graphics.h]库...我想初始化图形,所以我会这样做,所以自然地这样做:
initgraph(graphics_driver,graphics_mode,"") ;
Run Code Online (Sandbox Code Playgroud)
当我编译上面的代码时,它会给出错误"ISO C++禁止将字符串常量转换为char*"
我知道一个解决方法:
char c_array[] = "" ;
initgraph(graphics_driver,graphics_mode,c_array) ;
Run Code Online (Sandbox Code Playgroud)
上面编译得很好......这对于像...这样的函数是可以的initgraph(),因为我只会调用一次.但是,我想使用这样的outtextxy()函数(因为我在我的程序中多次调用它):
outtextxy(0,0,"Test") ;
Run Code Online (Sandbox Code Playgroud)
因为为所有不同的outtextxy()函数声明一个数组只会浪费空间.
那么,有没有办法使用上面没有数组或任何额外的变量?
PS:我在安装graphics.h库并配置所有链接器选项后使用代码块.等等...
谢谢,再见,塞缪尔