[英]OpenGL buffering two initializations
我的項目由兩個初始化組成,一個初始化用於用戶界面(菜單和按鈕),另一個初始化用於顯示圖片(位圖圖片),所有初始化均使用openGL編寫。 現在,小故障在哪里,當我構建它時,complier不會報告任何錯誤,但是我的應用程序沒有圖片,即沒有顯示它,但是顯示了用戶界面openGl對象。
首先,如您所見,我已經向要應用紋理的多邊形的頂點添加了紋理坐標,然后還應用了紋理的初始化以及它的集成,因此我看不到它的位置。 問題出在哪里? 並且,編譯器是否有可能以這種形式處理對象的集成,即是否可以使用不同的集成來緩沖兩個初始化?
/*
* Method InitUI() used for initialization of the user interface
*
*/
void InitUI()
{
myInterfaceSetDefaultStyle ( MYINTERFACESTYLE_SMALL_SHADED ) ;
myInterfaceSetDefaultColourScheme( 0.5f, 0.7f, 0.9f );
MenuFunctionA();
ButtonFUnctionA();
}
/*
* Method onDraw is used for integration of the cotures of the object itself
*
*/
void OnDraw() {
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
glLoadIdentity();
// binds the texture to any geometry about to be rendered
glBindTexture(GL_TEXTURE_2D,g_Texture);
// whenever you apply a texture to an object, you will need
// to specify texture co-ordinates which define the placement
// of the texture on the polygons. Changing the value of the
// tex coords changes the placement of the texture...
//
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2f(-15,15);
glTexCoord2f(0,1);
glVertex2f(-15,-15);
glTexCoord2f(1,1);
glVertex2f(15,-15);
glTexCoord2f(1,0);
glVertex2f(15,15);
glEnd();
glutSwapBuffers();
}
/*
* Method Display() used for making up of the user interface.
*
*/
void Display()
{
glClear(GL_COLOR_BUFFER_BIT);
/* display the user interface */
myInterfaceDisplay();
glutSwapBuffers();
}
/*
* Method OnInit() used for initialization of the texture bitmap
*/
void OnInit() {
// enable the depth test and 2D texturing
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
// load texture as compressed
g_Texture = LoadTexture("texture.bmp");
// outputs the size of the texture
// I used this method just to test if this function is integrated at all, and suprisingly it is, however no picture is displayed, even though I specifically stated it in this function
std::cout << "Texture Size=" << (GetTextureSize(g_Texture)/1024.0f) << "Kb"<< std::endl;
}
/*
* Method Init() used for custom OpenGL initialization ( background of the application )
*/
void Init()
{
glClearColor(0.5f,0.5f,0.5f,0.5f);
}
/*
* Method main used for integration and initialization of all the components involved in building the application
*/
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE);
glutInitWindowSize(640,480);
glutInitWindowPosition(300,100);
glutCreateWindow(" OpenGL Double buffering ");
glutDisplayFunc(Display);
glutDisplayFunc(onDraw);
glutMouseFunc(MouseButton);
glutMotionFunc(MouseMove);
glutKeyboardFunc(KeyBoard);
glutSpecialFunc(SpecialKeyBoard);
myInterfaceInit();
Init();
InitUI();
onInit();
glutMainLoop();
}
您一次只能使用GLUT注冊一個回調。 如果要調用多個功能,請通過代理功能執行此操作。
雙緩沖區用於在渲染第二個圖像之前顯示一個“圖像”。 然后交換它們並渲染第一個。
我會在一個針對glut的回調中做到這一點(glutDisplay不支持多個回調),例如:
void Display() {
glLoadIdentity();
DrawOne();
DrawOther();
glutSwapBuffers();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.