void glutInitWindowPosition(int x, int y);设置初始窗口的位置

void glutInitWindowPosition(int x, int y);

设置初始窗口的位置(窗口左上角相对于桌面坐标(x,y))


坐标(0,0)是指屏幕左上角的位置.

x,y单位均为像素.

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
【例3-2】使用glut库函数绘制一个真实感的球。 # include < GL/glut.h > /* 初始化材料属性、光源属性、光照模型,打开深度缓冲区等 */ void init(void) { GLfloat light_position [ ] = { 1.0, 1.0, 1.0, 0.0 }; glClearColor ( 0.0, 0.0, 1.0, 0.0 );//设置背景色为蓝色 glShadeModel ( GL_SMOOTH ); glLightfv ( GL_LIGHT0, GL_POSITION, light_position); glEnable (GL_LIGHTING); glEnable (GL_LIGHT0); glEnable (GL_DEPTH_TEST); } /*调用GLUT函数,绘制一个球*/ void display ( void ) { glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glutSolidSphere (1.0, 40, 50); //半径为1,40条纬线,50条经线 glFlush (); } /* 定义GLUT的reshape函数,w、h分别是输出图形的窗口的宽和高*/ 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 ( ) ; } int main(int argc, char** argv) { glutInit (&argc, argv); // GLUT环境初始glutInitDisplayMode (GLUT_SINGLE |GLUT_RGB |GLUT_DEPTH); // 显示模式初始glutInitWindowSize (300, 300); // 定义窗口大小 glutInitWindowPosition (100, 100); // 定义窗口位置 glutCreateWindow ( argv [ 0 ] ); // 显示窗口窗口标题为执行函数名 init( ); // 调用init函数 glutDisplayFunc ( display ); // 注册OpenGL绘图函数(一种的特殊调用方式,下同) glutReshapeFunc ( reshape ); // 注册窗口大小改变时的响应函数 glutMainLoop( ); // 进入GLUT消息循环,开始执行程序 return 0; }
#define _USE_MATH_DEFINES #include <cstdlib> #include <cmath> #include <iostream> #include <GL/glew.h> #include <GL/freeglut.h> // Globals. static float R = 40.0; // Radius of circle. static float X = 50.0; // X-coordinate of center of circle. static float Y = 50.0; // Y-coordinate of center of circle. static const int numVertices = 50; // Number of vertices on circle. static int verticesColors[6 * numVertices]; void generateVertices() { float t = 0; // Angle parameter. for (int i = 0; i < 6 * numVertices; i += 6) { verticesColors[i] = X + R * cos(t); //x verticesColors[i] = Y + R * sin(t); //y verticesColors[i] = 0.0; //z verticesColors[i] = 1.0; //r verticesColors[i] = 0.0; //g verticesColors[i] = 0.0; //b t += 2 * M_PI / numVertices; //angle } } // Drawing routine. void drawScene(void) { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1, 0, 0); glLineWidth(5); glDrawArrays(GL_POLYGON, 0, numVertices); glFlush(); } // Initialization routine. void setup(void) { glClearColor(1.0, 1.0, 1.0, 0.0); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glColorPointer(3, GL_FLOAT, 6 * sizeof(float), &verticesColors[0]); glVertexPointer(3, GL_FLOAT, 6 * sizeof(float), &verticesColors[3]); } // OpenGL window reshape routine. void resize(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 100.0, 0.0, 100.0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } // Keyboard input processing routine. void keyInput(unsigned char key, int x, int y) { switch (key) { case 27: exit(0); break; default: break; } } // Main routine. int main(int argc, char** argv) { generateVertices(); glutInit(&argc, argv); glutInitContextVersion(4, 3); glutInitContextProfile(GLUT_COMPATIBILITY_PROFILE); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); glutInitWindowSize(500, 500); glutInitWindowPosition(100, 100); glutCreateWindow("circle.cpp"); glutDisplayFunc(drawScene); glutReshapeFunc(resize); glutKeyboardFunc(keyInput); glewExperimental = GL_TRUE; glewInit(); setup(); glutMainLoop(); }
最新发布
05-25

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值