无法在openGL

时间:2015-11-10 12:21:53

标签: c opengl

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

我一直在使用的代码如下。谢谢

#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;
}

0 个答案:

没有答案