首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络技术 > 网络协议 >

opengl出现的不惑之年.

2013-01-01 
opengl出现的不惑...下面是我写的一个小的Opengl程序,原本是打算是在白色的矩形区域内画四个不同颜色的点,

opengl出现的不惑...
下面是我写的一个小的Opengl程序,原本是打算是在白色的矩形区域内画四个不同颜色的点,但是却出现了一个绿色区域内的四个点,求解释啊。。下面是我的代码:
#include <gl/glut.h>
void display(){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
    glBegin(GL_POLYGON);
   glVertex2f(-2,-1);
   glVertex2f(-2,-2);
   glVertex2f(-1,0);
   glVertex2f(-4,-2);
glEnd();
    glPointSize(2.0);
glBegin(GL_POINTS);
  glColor3f(1.0,1.0,1.0);
  glVertex2f(-0.5,-0.5);
  glColor3f(1.0,0.0,0.0);
  glVertex2f(-0.5,0.5);    
  glColor3f(0.0,0.0,0.0);
  glVertex2f(0.5,0.5);
  glColor3f(0.0,1.0,0.0);
  glVertex2f(0.5,-0.5);
glEnd();
glFlush();
}
void init()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1.0,1.0,-1.0,1.0);
}
int main(int argc,char **argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(0,0);
glutInitWindowSize(500,500);
glutCreateWindow("simple");
glutDisplayFunc(display);
init();
glutMainLoop();
}

。。。各位大虾给个解释吧。。。。
[解决办法]
你画的矩形不在屏幕坐标范围内.
可改为


//白色区域
glColor3f(1.0,1.0,1.0);
glBegin(GL_POLYGON);
glVertex2f(-0.75,-0.75);
glVertex2f(0.75,-0.75);
glVertex2f(0.75,0.75);
glVertex2f(-0.75,0.75);
glEnd();

glPointSize(2.0);
glBegin(GL_POINTS);
glColor3f(0.0,0.0,0.0);//黑
glVertex2f(-0.5,-0.5);
glColor3f(1.0,0.0,0.0);//红
glVertex2f(-0.5,0.5);   
glColor3f(0.0,0.0,1.0);//蓝
glVertex2f(0.5,0.5);
glColor3f(0.0,1.0,0.0);//绿
glVertex2f(0.5,-0.5);
glEnd();
glFlush();

多看看红宝书吧
[解决办法]
gluOrtho2D(-1.0,1.0,-1.0,1.0)

有效区域是(-1.0,1.0,-1.0,1.0)

热点排行