#include <GLUT/GLUT.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor4f(0.0,1,0,0.5);
glRectf(0.1,0.1,0.6,0.6);
glColor4f(1.0,1,0,0.7);
glRectf(0.4,0.3,0.6,0.6);
glFlush();
}
void init()
{
glEnable (GL_BLEND); //啓用融合
glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);//產生融合因子
glShadeModel (GL_FLAT);//設置平面明暗處理
glClearColor (0.0,0.0,0.0,0.0);//清屏
}
void reshape (int w,int h)
{
glViewport (0,0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
if (w <= h)
glOrtho (-1.5,1.5, -1.5*(GLfloat)h/(GLfloat)w,
1.5*(GLfloat)h/(GLfloat)w, -10.0,10.0);
else
glOrtho (-1.5*(GLfloat)w/(GLfloat)h,
1.5*(GLfloat)w/(GLfloat)h, -1.5,1.5, -10.0,10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
把這裏的const 去掉就好了
或者 glutInit(&argc, const_cast<char**>(argv));
//int main(int argc, const char * argv[])
int main(int argc,char * argv[]) {
// insert code here...
//std::cout << "Hello, World!\n";
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE |GLUT_RGB |GLUT_DEPTH);
glutInitWindowSize (500,500);
glutInitWindowPosition (300,300);
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return0;
}