我在创建1列网格的代码部分遇到了麻烦。
我正在创建2个具有坐标值的数组。 x坐标存储在x数组中,y坐标值存储在y数组中。问题是:虽然我正在修改数组x的值,但它有一些其他值,我没有得到req输出。
我希望2 x坐标之间的距离为60,但我得到了一些其他值。
试试这段代码告诉我哪里出错了。
#include<stdio.h>
#include<stdlib.h>
#include<GL/gl.h>
#include<GL/glu.h>
#include<GL/glut.h>
void drawBitmapText(char *font,char *string,float x,float y)
{
char *c;
glRasterPos3f(x, y,0.0);
for (c=string; *c != '\0'; c++)
{
glutBitmapCharacter(font, *c);
}
}
void drawBitmapInt(char *font,int i,float x,float y)
{
char buffer[10]={'\0'};
char *c;
sprintf(buffer, "%d", i);
glRasterPos3f(x, y,0.0);
for (c=buffer; *c != '\0'; c++)
{
glutBitmapCharacter(font, *c);
}
}
void MainMem()
{
int i,j,xo=100,yo=0,k=12,x1[2],y[12];
int dx=60,dy=50;
for(j=0;j<13;j++)
{
y[j]=0;
}
for(i=0;i<2;i++)
{
x1[i]=xo+i*dx;
printf(" %d %d", x1[0],x1[1]);
}
x1[i]=0;
for(j=0;j<13;j++)
{
y[j]=yo+j*dy;
}
y[j]=0;
glBegin(GL_LINE_LOOP);
for(j=0;j<13;j++)
{
glColor3f(0,1,0);
printf("\n%d %d",x1[0],x1[1]);
glVertex2i(x1[0],y[j]+260);
glVertex2i(x1[1],y[j]+260);
glVertex2i(x1[1],y[j+1]+260);
glVertex2i(x1[0],y[j+1]+260);
}
glEnd();
for(i=0;i<1;i++)
for(j=0;j<13;j++)
{
drawBitmapInt(GLUT_BITMAP_HELVETICA_18,k--,x1[0]+730,265+j*50);
}
}
void displayPoints()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.1,0.7,0.1);
MainMem();
glFlush();
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutCreateWindow("SampleGL");
glutInitWindowSize(2000,1000);
glClearColor(1.0,1.0,1.0,0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0,2000,0.0,1000);
glutDisplayFunc(displayPoints);
glutMainLoop();
}