三种方法绘制矩形 源代码

#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);
}
C++语言矩形 "_AFXDLL" "E:\E03教学\2011下半年\图形学\计算机图形学基础教程(Visual C++版)\第五章\案例9-二维基本几何变换算法\Test.rc"" Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP8A.tmp" with contents [ /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /Fp"Debug/Test.pch" /Yu"stdafx.h" /Fo"Debug/" /Fd"Debug/" /FD /GZ /c "E:\E03教学\2011下半年\图形学\计算机图形学基础教程(Visual C++版)\第五章\案例9-二维基本几何变换算法\MainFrm.cpp" "E:\E03教学\2011下半年\图形学\计算机图形学基础教程(Visual C++版)\第五章\案例9-二维基本几何变换算法\Picdlg.cpp" "E:\E03教学\2011下半年\图形学\计算机图形学基础教程(Visual C++版)\第五章\案例9-二维基本几何变换算法\Test.cpp" "E:\E03教学\2011下半年\图形学\计算机图形学基础教程(Visual C++版)\第五章\案例9-二维基本几何变换算法\TestDoc.cpp" "E:\E03教学\2011下半年\图形学\计算机图形学基础教程(Visual C++版)\第五章\案例9-二维基本几何变换算法\TestView.cpp" ] Creating command line "cl.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP8A.tmp" Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP8B.tmp" with contents [ /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /Fp"Debug/Test.pch" /Yc"stdafx.h" /Fo"Debug/" /Fd"Debug/" /FD /GZ /c "E:\E03教学\2011下半年\图形学\计算机图形学基础教程(Visual C++版)\第五章\案例9-二维基本几何变换算法\StdAfx.cpp" ] Creating command line "cl.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP8B.tmp" Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP8C.tmp" with contents [ /nologo /subsystem:windows /incremental:yes /pdb:"Debug/Test.pdb" /debug /machine:I386 /out:"Debug/Test.exe" /pdbtype:sept ".\Debug\MainFrm.obj" ".\Debug\Picdlg.obj" ".\Debug\StdAfx.obj" ".\Debug\Test.obj" ".\Debug\TestDoc.obj" ".\Debug\TestView.obj" ".\Debug\Test.res" ] Creating command line "link.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP8C.tmp" <h3>Output Window</h3> Compiling resources... Compiling... StdAfx.cpp Compiling... MainFrm.cpp Picdlg.cpp Test.cpp TestDoc.cpp TestView.cpp Generating Code... Linking...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值