具体要求
(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
最新发布