2012-04-17 82 views
-2

我在OpenGL中渲染一個帶有一些地圖圖像的場景,並直接使用地圖的lat,lon作爲座標。所以我的場景不是從0,0開始,而是上升到寬度,高度。儘管我可以看到我的多邊形(非常小),但我無法通過更改gluLookAt()中的眼睛的z值來進行縮放。OpenGL透視投影和攝像機位置

/* 
* My boundary for map quad with texture 
*/ 
#define TOP 41.9061 
#define BOTTOM 41.8546 
#define LEFT -87.7012 
#define RIGHT -87.6054 

/* 
* window size 
*/ 
const unsigned int window_width = 1024; 
const unsigned int window_height = 739; 

/* 
* drawing a polygon with texture 
*/ 
glEnable(GL_TEXTURE_2D); 
glBindTexture(GL_TEXTURE_2D, mainMapTextureId); 
glBegin(GL_POLYGON); 
//bottom left 
glTexCoord2f(0.0f, 1.0f); 
glVertex3f(LEFT, BOTTOM, 0.0); 

//bottom right 
glTexCoord2f(1.0f, 1.0f); 
glVertex3f(RIGHT, BOTTOM, 0.0); 

//top right 
glTexCoord2f(1.0f, 0.0f); 
glVertex3f(RIGHT, TOP, 0.0); 

//top left 
glTexCoord2f(0.0f, 0.0f); 
glVertex3f(LEFT, TOP, 0.0); 
glEnd(); 


/* 
* Setting up the camera 
*/ 
glMatrixMode(GL_PROJECTION); 
glLoadIdentity(); 
gluPerspective(60.0, (GLfloat)window_width/(GLfloat)window_height, 0.0, 10.0); 
gluLookAt((float)(LEFT+RIGHT)/2.0, (float)(TOP+BOTTOM)/2.0, 1.0, 
       (float)(LEFT+RIGHT)/2.0, (float)(TOP+BOTTOM)/2.0, 0.0, 
     0.0f, 1.0f, 0.0f); 

回答

2

gluPerspective的近平面的值爲0.0是不合法的。嘗試用一個標稱的小值(0.1f)替換它。

還總是在你的代碼中放一個glGetError調用,它會提醒你一些問題。

+0

非常感謝。有效。 – musa 2012-04-17 20:21:41