Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 谢尔宾斯基垫圈_C++_Opengl - Fatal编程技术网

C++ 谢尔宾斯基垫圈

C++ 谢尔宾斯基垫圈,c++,opengl,C++,Opengl,我在用C/C++编写代码时遇到了一个错误 #include "glut.h" #include <random> // Classes and structs // struct GLPoint { GLfloat x, y; }; // Method(s) Declration // void drawDot(GLfloat, GLfloat); void serpinski_render(void); void myInti(void); // Method(

我在用C/C++编写代码时遇到了一个错误

#include "glut.h"
#include <random>

// Classes and structs // 
struct GLPoint {
    GLfloat x, y;
};

// Method(s) Declration // 
void drawDot(GLfloat, GLfloat);
void serpinski_render(void);
void myInti(void); 

// Method(s) Implementation // 
void drawDot(GLfloat x, GLfloat y){
    glBegin(GL_POINTS);
    glVertex2i(x, y);
    glEnd();
}
void serpinski_render(void)
{
    glClear(GL_COLOR_BUFFER_BIT);  // Clear the screen from anything is displayed on it 
    GLPoint T[3] = { { 10, 10 }, { 600, 10 }, { 300, 600 } }; // the three points of parent triangle 

    int index = rand() % 3;  // this mean i will choose a random number between 0 , 3 
    GLPoint point = T[index];
    drawDot(point.x, point.y);

    for (unsigned int i = 0; i < 5500; i++) // a loop that going to run 5500 ( a very big number ) 
    {
        index = rand() % 3;
        point.x = (point.x + T[index].x) / 2;
        point.y = (point.y + T[index].y) / 2;

        drawDot(point.x, point.y); 
    }
    glFlush(); 

}
void myInti(void)
{
    glClearColor(1, 1, 1, 0);  // a white background 
    glColor3f(0, 0, 0); // black points 
    glPointSize(3); // 3 pixel point size 

    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 
    gluOrtho2D(0, 640, 0, 480); 
}


// Main Method //
void main(int argc ,char ** argv )
{
    glutInit(&argc, argv); // intilize toolkit 
    glutInitWindowPosition(100, 150); 
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); 
    glutInitWindowSize(640, 480); // windows size is 640 x 480 
    glutDisplayFunc(serpinski_render); 

    myInti(); 
    glutMainLoop(); 
}
#包括“glut.h”
#包括
//类和结构//
结构GLPoint{
glx,y;
};
//方法确定//
无效drawDot(GLfloat,GLfloat);
无效serpinski_渲染(无效);
无效myInti(无效);
//方法实现//
空心绘图点(GLfloat x、GLfloat y){
glBegin(总分);
glVertex2i(x,y);
格伦德();
}
void serpinski_渲染(void)
{
glClear(GL_COLOR_BUFFER_BIT);//清除屏幕上显示的任何内容
GLPoint T[3]={{10,10},{600,10},{300,600};//父三角形的三个点
int index=rand()%3;//这意味着我将在0和3之间选择一个随机数
GLPoint点=T[指数];
绘图点(点x、点y);
for(unsigned int i=0;i<5500;i++)//一个将运行5500的循环(一个非常大的数字)
{
索引=rand()%3;
点x=(点x+T[index].x)/2;
点.y=(点.y+T[index].y)/2;
绘图点(点x、点y);
}
glFlush();
}
void myInti(void)
{
glClearColor(1,1,1,0);//白色背景
glColor3f(0,0,0);//黑点
glPointSize(3);//3像素点大小
glMatrixMode(GL_投影);
glLoadIdentity();
gluOrtho2D(0640,0480);
}
//主要方法//
void main(整型argc,字符**argv)
{
glutInit(&argc,argv);//初始化工具箱
位置(100150);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
GLUTINITWindowsSize(640480);//窗口大小为640x480
glutDisplayFunc(serpinski_渲染);
myInti();
glutMainLoop();
}
我不知道它是否能正常工作,但这段代码应该会生成Sierpinski三角形。 而且我每次面对C++库时都会随机地在STDLIB中解决这个问题。
错误1错误C2381:“退出”:重新定义__declspec(noreturn)不同于c:\program files(x86)\microsoft visual studio 12.0\vc\include\stdlib.h 376

# ifndef GLUT_BUILDING_LIB
extern _CRTIMP void __cdecl exit(int);
# endif
glut.h
头非常旧。这可能是一个解决老VC缺陷的方法。Visual C现在似乎有一个声明与此声明冲突。简单的解决方案是从标题中删除这些行,因为在
stdlib.h
中有一个有效的定义

顺便说一下,所有的
glVertex
glBegin
glEnd
、矩阵堆栈和许多其他OpenGL调用都不赞成使用着色器


也许还有更新/更好的
glut
可用。我想检查一下。

glut.h和Visual Studio.NET之间存在不兼容,这是“glut.h”和您的情况下的用法。 您只需声明以下内容即可解决此问题:

#include <random>
#include "glut.h"

还请阅读glutCreateWindow函数。

注意,我已经在stack overflow non work上找到了一些关于此主题的帖子。比如包括stdliblook,比如库版本、glut和visualstudio之间存在冲突。尝试使用您的Visual Studio版本重建glut。尝试将
void main
更改为更合法的内容,如
int main()
并附加
return EXIT\u SUCCESS结束。关于使用visual studio重建我没有搜索到任何关于它的内容。。当我使用int main并返回EXIT_SUCCESS时;同样的错误可能重复:我最近换了一个新的/更好的
glut
。我尝试了简单的方法,但遗憾的是没有成功,我会马上检查glut的哦,我不相信它有那么简单我整天都在找谢谢先生。。你现在让我开心
#include "glut.h"
#include <random>
void main(int argc ,char ** argv )
{
    glutInit(&argc, argv); // intilize toolkit 
    glutInitWindowPosition(100, 150); 
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); 
    glutInitWindowSize(640, 480); // windows size is 640 x 480 
    glutCreateWindow("A title");
    myInti(); 
    glutDisplayFunc(serpinski_render); 

    glutMainLoop(); 
}