Dzek Trek
Dzek Trek

Reputation: 338

OpenGL buffering two initializations

My project is consisted of two initializations, one init is for the user interface ( menu and the buttons ) and the other one is for the displaying pictures( bitmap pics ), all written using openGL. Now, where is the glitch, when I build it, complier doesn't report any errors, but my app lacks picture, i.e. it doesn't show it, however my user interface openGl objects shows.

First of all, as you can see, I have added texture coordinates to the vertices of the polygons that I wanted to apply a texture to, then initialization of the texture is applied also, plus it's integration so I can't see where it stuck. Where does the problem lie? And, is it possible for compiler to handle integration of the objects in this form, i.e. is it possible to buffer two initializations using different integrations?

/*
 * 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();

}

Upvotes: 2

Views: 213

Answers (2)

Vyktor
Vyktor

Reputation: 21007

Double buffer is used to display one "image" before the second one is rendering. Then swap them and render the first one.

I'd do it in one callback for glut (glutDisplay doesn't support multiple callbacks), such as:

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

Upvotes: 2

datenwolf
datenwolf

Reputation: 162367

You can register only one callback at a time with GLUT. If you want to call multiple functions, do this through a proxy function.

Upvotes: 2

Related Questions