C 无法使用openGL中的GL_Line_Strip在循环中绘制线条条

C 无法使用openGL中的GL_Line_Strip在循环中绘制线条条,c,opengl,C,Opengl,我正在尝试使用GLUT和OpenGL中的GL_line_STRIP绘制一些线条条。我从两个指针(用于x和y)获取顶点输入,并使用for循环绘制它们。但是,我只得到最后两行作为我的输出(从(0,0)[我在指针中没有提到的坐标]到x0,y0),缺少线条带的所有其他顶点。它在显示方法中 下面给出了我一直在使用的代码。多谢各位 #ifdef __APPLE__ #include <GLUT/glut.h> #else #include <GL/glut.h> #endif #

我正在尝试使用GLUT和OpenGL中的GL_line_STRIP绘制一些线条条。我从两个指针(用于x和y)获取顶点输入,并使用for循环绘制它们。但是,我只得到最后两行作为我的输出(从(0,0)[我在指针中没有提到的坐标]到x0,y0),缺少线条带的所有其他顶点。它在显示方法中

下面给出了我一直在使用的代码。多谢各位

#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif


#include <stdlib.h>
#include "stdio.h"

int* pointValx;
int* pointValy;
int numPoint;


void displayCB(void)        /* function called whenever redisplay needed */
{
 glClear(GL_COLOR_BUFFER_BIT);      /* clear the display */
 glColor3f(1.0, 1.0, 1.0);      /* set current color to white */
 glPointSize(10.12);
 glBegin(GL_LINE_STRIP); //Begin triangle coordinates

 for(int i = 0; i < numPoint; i++)
 {
  glVertex2i(pointValx[i], pointValx[i]);
  printf("i >> %d\n",i);
 }
 glEnd(); //End Co-ord
 glFlush();
 glutSwapBuffers();
 }

 int takeInput()
{
printf("Screen Size is 0 - 400 in X and 0 - 500 in Y\n");
printf("Lab for Line and Point\n");
printf("number of lines >> \n");
scanf("%d",&numPoint); //comment this line for Line

pointValx = (int*)malloc(numPoint * sizeof(int));
pointValy = (int*)malloc(numPoint * sizeof(int));

printf("numPoint >> %d\n",numPoint);

for(int i = 0; i < numPoint;)
{
    int x,y;
    printf("Input for X >> %d\n", i);
    scanf("%d",&x);
    printf("numPoint >> %d\n",numPoint);
    if(x >= 0 && x <= 400)
    {
        printf("Input for Y >> %d\n", i);
        scanf("%d",&y);
        if(y >= 0 && y <= 500)
        {
            pointValx[i] = x;
            pointValy[i] = y;
            i++;
        }
        else
        {
            printf("Y value crossed the limit\n");
        }
    }
    else
    {
       printf("X value crossed the limit\n");
    }
 }

printf("End of Input file\n");
return -1;
}








int main(int argc, char *argv[])
 {
int win;

glutInit(&argc, argv);      /* initialize GLUT system */

glutInitDisplayMode(GLUT_RGB);
glutInitWindowSize(400,500);        /* width=400pixels height=500pixels */
win = glutCreateWindow("GL_LINES and Points");  /* create window */

/* from this point on the current window is win */
takeInput();

glClearColor(0.0,0.0,0.0,0.0);  /* set background to black */
gluOrtho2D(0,400,0,500);        /* how object is mapped to window */
glutDisplayFunc(displayCB);     /* set window's display callback */

glutMainLoop();         /* start processing events... */

/* execution never reaches this point */

free(pointValx);
free(pointValy);

return 0;
}
苹果公司__ #包括 #否则 #包括 #恩迪夫 #包括 #包括“stdio.h” int*pointValx; int*pointValy; int numPoint; 需要重新显示时调用void displayCB(void)/*函数*/ { glClear(GL_颜色_缓冲区_位);/*清除显示*/ glColor3f(1.0,1.0,1.0);/*将当前颜色设置为白色*/ glPointSize(10.12); glBegin(GL_LINE_STRIP);//开始三角形坐标 对于(int i=0;i>%d\n”,i); } 格伦德();//结束命令 glFlush(); glutSwapBuffers(); } inttakeinput() { printf(“屏幕尺寸为0-400英寸X和0-500英寸Y\n”); printf(“直线和点实验室”); printf(“行数>>\n”); scanf(“%d”,&numPoint);//对这一行进行注释 pointValx=(int*)malloc(numPoint*sizeof(int)); pointValy=(int*)malloc(numPoint*sizeof(int)); printf(“numPoint>>%d\n”,numPoint); 对于(int i=0;i>%d\n的输入”,i); scanf(“%d”和&x); printf(“numPoint>>%d\n”,numPoint);
如果(x>=0 & & x=0 & & y 1。这是纯C,其中没有一个C++位。2。代码> GLVTEX2i(PooToVx[i],PooToVxx[i])“<代码> >也许在某处应该有一个<代码> PooTalvy <代码> @谢谢你的回答。对不起,我的坏。我不确定C和C++之间的区别。我是本地java开发者。这是我第一次用C/C++在主()中工作。您使用glut初始化屏幕,只要求RGB颜色,默认情况下,RGB颜色是一个单缓冲窗口。在显示函数中,您同时使用flush()和glutSwapBuffers()。后者会导致flush()加上后台缓冲区的错误,因为只有一个缓冲区,即屏幕。如果你从java切换到另一种语言,选择一个并学习它。C(这是一个简单的语言,但是更多的是从java中删除),或者C++(一个更复杂的语言,但是稍微靠近java)对于C++,我们有一个可以抓取的起点。@ KostasRim,那么我应该保持FrHuSE()还是GLUWSWAPBUFER()?