您好,登錄后才能下訂單哦!
說明
gluOrtho2D(0.0, WINDOWWIDTH , WINDOWHEIGHT/2, 0.0);第三個參數取其一半,打點的Y坐標擴大了一倍.渲染直線的情況下,通過將第二參數和第三參數進行按比例尺放縮,實際上,可達到渲染圖形縮放的效果。所以gluOrtho2D函數定義了屏幕坐標多少個單位像素表示投影矩陣的單位一
代碼
#include <gl/glut.h>
#include <Windows.h>
#define WINDOWHEIGHT 480
#define WINDOWWIDTH 800
void myInit()
{
glClearColor(1.0,1.0,1.0,0.0);
glLineWidth(3.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//gluOrtho2D(0.0, WINDOWWIDTH, 0.0, WINDOWHEIGHT);
gluOrtho2D(0.0, WINDOWWIDTH , WINDOWHEIGHT/2, 0.0);
}
void myDisplay(void)
{
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glFlush();
}
void myMouse(int button,int state,int x,int y)
{
if(state==GLUT_DOWN)
{
glPointSize(10);
glBegin(GL_POINTS);
glColor3f(1.0f, 0.0f, 0.0f);
//glVertex2f(x, WINDOWHEIGHT-y);
glVertex2f(x, y);
glEnd();
glFlush();
}
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE);
glutInitWindowSize(WINDOWWIDTH, WINDOWHEIGHT);
glutInitWindowPosition(100,150);
glutCreateWindow("OpenGL 窗口1");
glutDisplayFunc(&myDisplay);
glutMouseFunc(&myMouse);
myInit();
glutMainLoop();
return 0;
}
代碼2
#include <gl/glut.h>
#include <Windows.h>
#define WINDOWHEIGHT 480
#define WINDOWWIDTH 800
void myInit(int scale)
{
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glFlush();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, WINDOWWIDTH/scale , WINDOWHEIGHT/scale, 0.0);
}
void myDisplay(void)
{
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glFlush();
}
void myMouse(int button,int state,int x,int y)
{
static int scale = 2;
if(state==GLUT_DOWN)
{
myInit(scale);
scale = scale + 2;
glLineWidth(10);
glBegin(GL_LINES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(10, 10);
glVertex2f(20, 20);
glEnd();
glFlush();
}
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE);
glutInitWindowSize(WINDOWWIDTH, WINDOWHEIGHT);
glutInitWindowPosition(100,150);
glutCreateWindow("OpenGL 窗口1");
glutDisplayFunc(&myDisplay);
glutMouseFunc(&myMouse);
glutMainLoop();
return 0;
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。