Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/144.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++ OpenGL正方形和箭头_C++_Opengl - Fatal编程技术网

C++ OpenGL正方形和箭头

C++ OpenGL正方形和箭头,c++,opengl,C++,Opengl,我试图创建一个正方形,在上面我创建了一个箭头。它就像一个2D米,类似的东西。但我不知道如何在正方形顶部创建箭头 int count = 1; for (float y = 1; y < 11; y++) { y1 = y1 - 0.51; y2 = y2 - 0.51; float x2 = -2.0; for (float x1 = -2.5; x1 < 2.5; x1 = x1 + 0.51) { glColor3f(windy

我试图创建一个正方形,在上面我创建了一个箭头。它就像一个2D米,类似的东西。但我不知道如何在正方形顶部创建箭头

int count = 1;
for (float y = 1; y < 11; y++) {
    y1 = y1 - 0.51;
    y2 = y2 - 0.51;

    float x2 = -2.0;
    for (float x1 = -2.5; x1 < 2.5; x1 = x1 + 0.51) {

        glColor3f(windy[count], 1.0, 0.0);
        glVertex2f(x1, y1);
        glVertex2f(x1, y2);
        glVertex2f(x2, y2);
        glVertex2f(x2, y1);
        count = count + 1;
        x2 = x2 + 0.51;



    }
}

glutSwapBuffers();
glEnd(); //End the glBegin Function

为什么在调用
glEnd()
之前要交换缓冲区:

int count = 1;
for (float y = 1; y < 11; y++) {
    y1 = y1 - 0.51;
    y2 = y2 - 0.51;

    float x2 = -2.0;
    for (float x1 = -2.5; x1 < 2.5; x1 = x1 + 0.51) {

        glColor3f(windy[count], 1.0, 0.0);
        glVertex2f(x1, y1);
        glVertex2f(x1, y2);
        glVertex2f(x2, y2);
        glVertex2f(x2, y1);
        count = count + 1;
        x2 = x2 + 0.51;
    }
}

//glutSwapBuffers(); // wrong place
glEnd(); //End the glBegin Function
glutSwapBuffers(); // Must be after draw operation
int count=1;
用于(浮动y=1;y<11;y++){
y1=y1-0.51;
y2=y2-0.51;
浮动x2=-2.0;
对于(浮点x1=-2.5;x1<2.5;x1=x1+0.51){
glColor3f(风[计数],1.0,0.0);
glVertex2f(x1,y1);
glVertex2f(x1,y2);
glVertex2f(x2,y2);
glVertex2f(x2,y1);
计数=计数+1;
x2=x2+0.51;
}
}
//glutSwapBuffers();//错误的地方
格伦德()//结束glBegin函数
glutSwapBuffers();//必须在牵引操作后进行
要在形状的顶部绘制箭头,必须更加:

int count = 1;
for (float y = 1; y < 11; y++) {
    y1 = y1 - 0.51;
    y2 = y2 - 0.51;

    float x2 = -2.0;
    for (float x1 = -2.5; x1 < 2.5; x1 = x1 + 0.51) {

        glColor3f(windy[count], 1.0, 0.0);
        glVertex2f(x1, y1);
        glVertex2f(x1, y2);
        glVertex2f(x2, y2);
        glVertex2f(x2, y1);
        count = count + 1;
        x2 = x2 + 0.51;
    }
}

//glutSwapBuffers(); // wrong place
glEnd(); //End the glBegin Function

// draw arrow
glBegin(GL_LINE_LOOP);//start drawing a line loop
        glVertex3f(-1.0f, 0.0f, 0.0f);//left of window
        glVertex3f(0.0f, -1.0f, 0.0f);//bottom of window
        glVertex3f(1.0f, 0.0f, 0.0f);//right of window
        glVertex3f(0.0f, 1.0f, 0.0f);//top of window
        glEnd();//end drawing of line loo


// atlast we can swap our buffers
glutSwapBuffers(); // Must be after draw operation
int count=1;
用于(浮动y=1;y<11;y++){
y1=y1-0.51;
y2=y2-0.51;
浮动x2=-2.0;
对于(浮点x1=-2.5;x1<2.5;x1=x1+0.51){
glColor3f(风[计数],1.0,0.0);
glVertex2f(x1,y1);
glVertex2f(x1,y2);
glVertex2f(x2,y2);
glVertex2f(x2,y1);
计数=计数+1;
x2=x2+0.51;
}
}
//glutSwapBuffers();//错误的地方
格伦德()//结束glBegin函数
//拔箭
glBegin(GL_线_环)//开始画一个直线循环
glVertex3f(-1.0f,0.0f,0.0f)//窗口左侧
glVertex3f(0.0f,-1.0f,0.0f)//窗底
glVertex3f(1.0f,0.0f,0.0f)//窗口右侧
glVertex3f(0.0f,1.0f,0.0f)//窗顶
格伦德()//loo线端图
//至少我们可以交换缓冲区
glutSwapBuffers();//必须在牵引操作后进行

你不应该在
glBegin
glEnd
@Java\u新手:我的答案帮你了吗?@Java\u新手:我的答案帮你了吗?
int count = 1;
for (float y = 1; y < 11; y++) {
    y1 = y1 - 0.51;
    y2 = y2 - 0.51;

    float x2 = -2.0;
    for (float x1 = -2.5; x1 < 2.5; x1 = x1 + 0.51) {

        glColor3f(windy[count], 1.0, 0.0);
        glVertex2f(x1, y1);
        glVertex2f(x1, y2);
        glVertex2f(x2, y2);
        glVertex2f(x2, y1);
        count = count + 1;
        x2 = x2 + 0.51;
    }
}

//glutSwapBuffers(); // wrong place
glEnd(); //End the glBegin Function

// draw arrow
glBegin(GL_LINE_LOOP);//start drawing a line loop
        glVertex3f(-1.0f, 0.0f, 0.0f);//left of window
        glVertex3f(0.0f, -1.0f, 0.0f);//bottom of window
        glVertex3f(1.0f, 0.0f, 0.0f);//right of window
        glVertex3f(0.0f, 1.0f, 0.0f);//top of window
        glEnd();//end drawing of line loo


// atlast we can swap our buffers
glutSwapBuffers(); // Must be after draw operation