OpenGL缓冲两次初始化

时间:2012-01-14 22:42:49

标签: c++ opengl

我的项目由两个初始化组成,一个用于用户界面(菜单和按钮),另一个用于显示图片(位图图片),所有这些都是使用openGL编写的。现在,故障在哪里,当我构建它时,编译器不报告任何错误,但我的应用程序缺少图片,即它没有显示它,但是我的用户界面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();

}

2 个答案:

答案 0 :(得分:2)

您只能使用GLUT注册一次回调。如果要调用多个函数,请通过代理函数执行此操作。

答案 1 :(得分:2)

双缓冲区用于在第二个渲染之前显示一个“图像”。然后交换它们并渲染第一个。

我会在一次回调中做过剩(glutDisplay不支持多次回调),例如:

void Display() {
    glLoadIdentity();
    DrawOne();
    DrawOther();
    glutSwapBuffers();
}