GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: Add Line Numbers


A Paste by hailviral
#include "bmpload.h"

int subwin;
int mainwin;
GLuint textures[2]; // Storage for one texture.

void init()
{
glClearColor(0,0,0,0);//Background color here
}

void backround()
{
       loadbmp(textures, "image.bmp",0);  // Load our image in textures[0]
    glBindTexture(GL_TEXTURE_2D, textures[0]); // Bind inage from texture[0]
    
    glEnable(GL_TEXTURE_2D); // Start texturing on polygon
    glBegin(GL_QUADS);// Just create a simple square
    glTexCoord2f(0,1); glVertex2f(-4,4);  //(Upper left corner)
    glTexCoord2f(1,1); glVertex2f(4,4);   //(Upper right corner)
    glTexCoord2f(1,0); glVertex2f(4,-4);  //(Lower right corner)
    glTexCoord2f(0,0); glVertex2f(-4,-4); //(Lower left corner)
    glEnd();
    glDisable(GL_TEXTURE_2D); // Stop Texturing

    glutSwapBuffers(); //Swap the front buffer (the visible buffer) and back buffer(the invisible buffer)
    glFlush(); // Draw everything to the screen
}

void display2()
{
    loadbmp(textures, "imagee.bmp",1);  // Load our image in textures[0]
    glBindTexture(GL_TEXTURE_2D, textures[1]); // Used to select the texture out of array
    
    glEnable(GL_TEXTURE_2D); // Start texturing
    glBegin(GL_QUADS);// Just create a simple square
    glTexCoord2f(0,1); glVertex2f(-4,4);  //(Upper left corner)
    glTexCoord2f(1,1); glVertex2f(4,4);   //(Upper right corner)
    glTexCoord2f(1,0); glVertex2f(4,-4);  //(Lower right corner)
    glTexCoord2f(0,0); glVertex2f(-4,-4); //(Lower left corner)
    glEnd();
    glDisable(GL_TEXTURE_2D); // Stop Texturing
    
    glutSwapBuffers();
    glFlush();
  }

void keyboard(unsigned char key, int x, int y)
{
    switch(key)//(NEW) use a switch statement
    {
    case 1:
    glutDestroyWindow(mainwin);
        break;
    case 2:

        break;
   }
}
 
int main(int argc, char ** argv)
{
    glutInit(&argc, argv);
    glutInitWindowSize(800,600);
    glutInitWindowPosition(10,50);
       glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); // Use "Double Buffer" Draw on back buffer then sent to front

     mainwin = glutCreateWindow("Lesson 5"); // Main Window        
     init();                     // Must load image onto a polygon
     glutDisplayFunc(backround); // Load polygon with Image
   
    subwin = glutCreateSubWindow(mainwin, 50,10,200,200); // Sub Windows(place x,y(size x,y))
    init(); 
    glutDisplayFunc(display2);
  
    glutKeyboardFunc(keyboard);
    glutMainLoop();
 return 0; 
 }