void glutInitWindowSize(int width, int height);设置初始窗口的大小

本文介绍如何使用函数voidglutInitWindowSize(int width,int height)来设置OpenGL初始窗口的大小。宽度和高度均以像素为单位。
void glutInitWindowSize(int width, int height);

设置初始窗口的大小


width:宽度,单位是像素

height:高度,单位也是像素

帮我注释以下代码#include <GL/glut.h> #include <math.h> GLfloat theta = 0; void init() { glClearColor(1.0, 0.0, 0.0, 0.0); glShadeModel(GL_SMOOTH); glMatrixMode(GL_PROJECTION); gluOrtho2D(-2.0, 2.0, -2.0, 2.0); glMatrixMode(GL_MODELVIEW); } void mydraw() { glBegin(GL_TRIANGLES); glColor3f(1.0, 0.0, 0.0); glVertex3f(0.0, 1.0, 0.0); glColor3f(0.0, 1.0, 0.0); glVertex3f(0.0, 0.0, 0.0); glColor3f(0.0, 0.0, 1.0); glVertex3f(0.5, 0.5, 0.0); glEnd(); } void Mydisplay(void) { glClear(GL_COLOR_BUFFER_BIT); void glPushMatrix(void); mydraw(); void glPopMatrix(void); void glPushMatrix(void); glRotatef(theta, 0.0, 0.0, 1.0); mydraw(); void glPopMatrix(void); void glPushMatrix(void); glRotatef(theta, 0.0, 0.0, 1.0); mydraw(); void glPopMatrix(void); void glPushMatrix(void); glRotatef(theta, 0.0, 0.0, 1.0); mydraw(); void glPopMatrix(void); glFlush(); } void MyIdle(void) { theta += 15; if (theta >= 360) theta = 0; glutPostRedisplay(); } void reshape(int width, int height) { glViewport(0, 0, (GLsizei)width, (GLsizei)height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0, (GLfloat)width / (GLfloat)height, 1.0, 100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0, 0.0, -3.0); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(500, 500); glutInitWindowPosition(100, 100); glutCreateWindow("动画"); init(); glutDisplayFunc(Mydisplay); glutReshapeFunc(reshape); glutIdleFunc(&MyIdle); glutMainLoop(); return 0; }
05-10
具体要求 (1) 直线颜色为绿色(0.0f,1.0f,0.0f), 线粗为1; (2) 实现一般直线(所有斜率情况)的绘制算法,并将代码填写在函数void Line(int x0, int y0, int x1, int y1)中; (3) 绘制一个五角星来测试上述直线绘制算法,并将代码填写在函数void myDisplay(void)中指定位置。五角星的顶点坐标分别为:(261, 215), (344, 275),(429, 213), (398, 319), (477, 384), (378, 384), (344, 491), (310, 384), (209, 384), (292, 319). 利用OpenGL画点函数来实现一般直线(所有斜率情况)的绘制算法。// 提示:写完代码请保存之后再进行评测 #include <GL/freeglut.h> //#include <algorithm> #include <stdio.h> using namespace std; // 评测代码所用头文件-开始 #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> // 评测代码所用头文件-结束 void Line(int x0, int y0, int x1, int y1) { // 请在此添加你的代码 /********** Begin ********/ /********** End **********/ } void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT); // 请在此添加你的代码用来测试直线绘制代码 /********** Begin ********/ /********** End **********/ glFlush(); } void Init() { glClearColor(0.0, 0.0, 0.0, 0.0); glShadeModel(GL_SMOOTH); } void myReshape(int w, int h) { glViewport(0, 0, (GLsizei)w, (GLsizei)h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, (GLdouble)w, 0.0, (GLdouble)h); } int main(int argc, char *argv[]) { int width = 800; int height = 600; glutInit(&argc, argv); glutInitWindowPosition(100, 100); glutInitWindowSize(width, height); glutCreateWindow("Hello Line!"); Init(); glutDisplayFunc(myDisplay); glutReshapeFunc(myReshape); glutMainLoopEvent(); /*************以下为评测代码,与本次实验内容无关,请勿修改**************/ GLubyte* pPixelData = (GLubyte*)malloc(width * height * 3);//分配内存 GLint viewport[4] = {0}; glReadBuffer(GL_FRONT); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glGetIntegerv(GL_VIEWPORT, viewport); glReadPixels(viewport[0], viewport[1], viewport[2], viewport[3], GL_RGB, GL_UNSIGNED_BYTE, pPixelData); using namespace cv; Mat img; vector<cv::Mat> imgPlanes; img.create(height, width, CV_8UC3); split(img, imgPlanes); for(int i = 0; i < heig
最新发布
03-12
0<k<1直线绘制-DDA算法,具体要求 只考虑直线斜率<0k<1情况下,利用DDA算法生成一条直线,线粗为1,直线颜色为(1.0f,1.0f,0.0f),直线两端点坐标为(13,20)和(180,140)。// 提示:写完代码请保存之后再进行评测 #include <GL/freeglut.h> #include<stdio.h> // 评测代码所用头文件-开始 #include<opencv2/core/core.hpp> #include<opencv2/highgui/highgui.hpp> #include<opencv2/imgproc/imgproc.hpp> // 评测代码所用头文件-结束 void LineDDA(int x0, int y0, int x1, int y1) { // 请在此添加你的代码 /********** Begin ********/ /********** End **********/ } void myDisplay(void) { // 请在此添加你的代码 /********** Begin ********/ LineDDA( , , , ); /********** End **********/ glFlush(); } void Init() { glClearColor(0.0, 0.0, 0.0, 0.0); } void myReshape(int w, int h) { glViewport(0, 0, (GLsizei)w, (GLsizei)h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, (GLdouble)w, 0.0, (GLdouble)h); } int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitWindowPosition(100, 100); int width = 640; int height = 480; glutInitWindowSize(width,height); glutCreateWindow("Hello Line!"); Init(); glutDisplayFunc(myDisplay); glutReshapeFunc(myReshape); glutMainLoopEvent(); /*************以下为评测代码,与本次实验内容无关,请勿修改**************/ GLubyte* pPixelData = (GLubyte*)malloc(height * width * 4);//分配内存 GLint viewport[4] = {0}; glReadBuffer(GL_FRONT); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glGetIntegerv(GL_VIEWPORT, viewport); glReadPixels(viewport[0], viewport[1], viewport[2], viewport[3], GL_RGBA, GL_UNSIGNED_BYTE, pPixelData); cv::Mat img; std::vector<cv::Mat> imgPlanes; img.create(height, width, CV_8UC3); cv::split(img, imgPlanes); for(int i = 0; i < height; i++) { unsigned char* plane0Ptr = imgPlanes[0].ptr<unsigned char>(i); unsigned char* plane1Ptr = imgPlanes[1].ptr<unsigned char>(i); unsigned char* plane2Ptr = imgPlanes[2].ptr<unsigned char>(i); for(int j = 0; j < width; j ++) { int k = 4 * (i * width + j); plane2Ptr[j] = pPixelData[k];
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值