三种方法绘制矩形 源代码
2013-10-21 13:39
225 查看
#include<windows.h>
#include <gl/glut.h>
struct GLPoint{
GLint x, y;
};
const GLint screenWidth = 320;
const GLint screenHeight = 320;
const GLint xPosition = 100;
const GLint yPosition = 100;
void myDisplay(void);
void myInit(void);
void drawRectangleCenter(GLPoint pt,GLint widht,GLint height);
void drawRectangleCornersize(GLPoint pt,GLint width, GLdouble proportion);
int main(int argc, char ** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(screenWidth,screenHeight);
glutInitWindowPosition(xPosition,yPosition);
glutCreateWindow("ChessBoard");
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop();
return 0;
}
void drawRectangleCenter(GLPoint centerPoint,GLint width,GLint height){
glRecti(centerPoint.x-width/2,centerPoint.y-height/2,centerPoint.x+width/2,centerPoint.y+height/2);
}
void drawRectangleCornersize(GLPoint leftTopPoint,GLint width, GLdouble proportion){
//10, 290 300 3.75
//proportion = width / height
GLint x1,y1,x2,y2;
x1 = leftTopPoint.x; //10
y1 = leftTopPoint.y - (GLdouble)width/proportion; //210
x2 = leftTopPoint.x + width;
y2 = leftTopPoint.y;
//glRectf(x1,x2,y1,y2);
glRecti(x1,y1,x2,y2);
}
void myDisplay(void){
glClear(GL_COLOR_BUFFER_BIT);
//方法一:
glColor3f(0.7f,0.7f,0.7f);
glRecti(10,10,310,90);
//方法二:中心,高,宽
glColor3f(0.2f,0.2f,0.2f);
GLPoint centerPoint= {160,160};
GLint width= 300;
GLint height = 80;
drawRectangleCenter(centerPoint,width,height);
//方法三: 左上角,宽,宽长比
glColor3f(0.1f,0.1f,0.1f);
GLPoint leftTopPoint = {10,290};
GLdouble proportion = (GLdouble)width/height;
drawRectangleCornersize(leftTopPoint,width,proportion);
glFlush();
}
void myInit(void){
glClearColor(1.0,1.0,1.0,0.0);
glColor3f(0.0f,0.0f,0.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,(GLdouble)screenWidth,0.0,(GLdouble)screenHeight);
}
#include <gl/glut.h>
struct GLPoint{
GLint x, y;
};
const GLint screenWidth = 320;
const GLint screenHeight = 320;
const GLint xPosition = 100;
const GLint yPosition = 100;
void myDisplay(void);
void myInit(void);
void drawRectangleCenter(GLPoint pt,GLint widht,GLint height);
void drawRectangleCornersize(GLPoint pt,GLint width, GLdouble proportion);
int main(int argc, char ** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(screenWidth,screenHeight);
glutInitWindowPosition(xPosition,yPosition);
glutCreateWindow("ChessBoard");
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop();
return 0;
}
void drawRectangleCenter(GLPoint centerPoint,GLint width,GLint height){
glRecti(centerPoint.x-width/2,centerPoint.y-height/2,centerPoint.x+width/2,centerPoint.y+height/2);
}
void drawRectangleCornersize(GLPoint leftTopPoint,GLint width, GLdouble proportion){
//10, 290 300 3.75
//proportion = width / height
GLint x1,y1,x2,y2;
x1 = leftTopPoint.x; //10
y1 = leftTopPoint.y - (GLdouble)width/proportion; //210
x2 = leftTopPoint.x + width;
y2 = leftTopPoint.y;
//glRectf(x1,x2,y1,y2);
glRecti(x1,y1,x2,y2);
}
void myDisplay(void){
glClear(GL_COLOR_BUFFER_BIT);
//方法一:
glColor3f(0.7f,0.7f,0.7f);
glRecti(10,10,310,90);
//方法二:中心,高,宽
glColor3f(0.2f,0.2f,0.2f);
GLPoint centerPoint= {160,160};
GLint width= 300;
GLint height = 80;
drawRectangleCenter(centerPoint,width,height);
//方法三: 左上角,宽,宽长比
glColor3f(0.1f,0.1f,0.1f);
GLPoint leftTopPoint = {10,290};
GLdouble proportion = (GLdouble)width/height;
drawRectangleCornersize(leftTopPoint,width,proportion);
glFlush();
}
void myInit(void){
glClearColor(1.0,1.0,1.0,0.0);
glColor3f(0.0f,0.0f,0.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,(GLdouble)screenWidth,0.0,(GLdouble)screenHeight);
}
相关文章推荐
- GDI+绘制自定义行距的文本的三种方法。
- 详解微信小程序canvas圆角矩形的绘制的方法
- android View的绘制过程和获取组件高宽值的三种方法
- wpf 分别用前台和后台 两种方法 绘制矩形 填充
- iOS 绘制虚线的三种方法
- 使用鼠标左键点击绘制一个矩形 右键清屏 源代码
- WPF学习(一)绘制图形的三种方法及区别
- drawRoundRect方法:绘制圆角矩形
- 在winform中绘制矩形的方法
- autocad2014绘制矩形和正多边形的简单方法
- [iOS 绘制虚线] 转: iOS 绘制虚线的三种方法
- 绘制渐变矩形的一种方法
- WPF学习(一)绘制图形的三种方法及区别
- autocad2014绘制矩形和正多边形的简单方法
- wpf 分别用前台和后台 两种方法 绘制矩形 填充
- js+canvas绘制矩形的方法
- Graphics类提供基本的几何图形绘制方法,主要有:画线段、画矩形、画圆、画带颜色的图形、画椭圆、画圆弧、画多边形等。
- 使用Gephi绘制动态网络的三种方法
- Android 绘制圆图片的三种个方法
- php绘制一个矩形的方法