void VideoViewer::initializeGL()
{

    glEnable(GL_VERTEX_ARRAY);
    glEnable(GL_TEXTURE_2D);

    makeShaders();
    makeGeometry();
    //updateTexture();

    glGenTextures(1, &_textureId);
    glBindTexture(GL_TEXTURE_2D, _textureId);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,     GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,     GL_CLAMP_TO_EDGE);

}
Esempio n. 2
0
/*
 Initializes opengl states
 */
void glutWidget::initOpenGL()
{
    glewExperimental = GL_TRUE; 
    GLenum err = glewInit();                             //initialize GLEW - this enables us to use extensions
    if(err != GLEW_OK)
    {
        std::cout << "ERROR: Loading GLEW failed." << std::endl;
        exit(-1);
    }
    checkExtensions();
    glClearColor(1.0f, 1.0f, 1.0f, 1.0f);   //default "empty"/background color is set to white
    
    glEnable(GL_CULL_FACE);
    glEnable(GL_DEPTH_TEST);
    
    
    makeShaders();          //load data of fragment and vertex programs/shaders - compile shaders
    
    srand(time(NULL));
    
    color = rand() % 100 + 1;
}
Esempio n. 3
0
/*
 Initializes opengl states
 */
void glutWidget::initOpenGL()
{
    glewExperimental = GL_TRUE; 
    GLenum err = glewInit();                             //initialize GLEW - this enables us to use extensions
    if(err != GLEW_OK)
    {
        std::cout << "ERROR: Loading GLEW failed." << std::endl;
        exit(-1);
    }
    checkExtensions();
    glClearColor(1, 1, 1, 0);   //default "empty"/background color is set to white
    
    glEnable(GL_DEPTH_TEST);
    
    CBitmap skybox("skybox.bmp");               //read bitmap image
    glGenTextures(1, &m_texture);               //allocate 1 texture
    glUniform1i(skybox_texture, 0);			        //pass texture location to vertex shader
    glBindTexture(GL_TEXTURE_2D, skybox_texture);    //bind this texture to be active
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, skybox.GetWidth(), skybox.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, skybox.GetBits());

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);   //specify minificaton filtering
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);   //specify magnificaton filtering
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);        //specify texture coordinate treatment
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);        //specify texture coordinate treatment
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);        //specify texture coordinate treatment
    
    glBindTexture(GL_TEXTURE_2D, 0);
    
    CBitmap streets("streets.bmp");               //read bitmap image
    glGenTextures(1, &street_texture);          //allocate 1 texture
    glUniform1i(street_texture, 0);			        //pass texture location to vertex shader
    glBindTexture(GL_TEXTURE_2D, street_texture);    //bind this texture to be active
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, streets.GetWidth(), streets.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, streets.GetBits());

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);   //specify minificaton filtering
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);   //specify magnificaton filtering
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);        //specify texture coordinate treatment
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);        //specify texture coordinate treatment


    glBindTexture(GL_TEXTURE_2D, 0);    //bind default texture to be active
    
    CBitmap car("car.bmp");               //read bitmap image
    glGenTextures(1, &car_texture);          //allocate 1 texture
    glUniform1i(car_texture, 0);			        //pass texture location to vertex shader
    glBindTexture(GL_TEXTURE_2D, car_texture);    //bind this texture to be active
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, car.GetWidth(), car.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, car.GetBits());

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);   //specify minificaton filtering
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);   //specify magnificaton filtering
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);        //specify texture coordinate treatment
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);        //specify texture coordinate treatment
    
    glBindTexture(GL_TEXTURE_2D, 0);    //bind default texture to be active
    
    CBitmap structure("structure.bmp");               //read bitmap image
    glGenTextures(1, &structure_texture);          //allocate 1 texture
    glUniform1i(structure_texture, 0);			        //pass texture location to vertex shader
    glBindTexture(GL_TEXTURE_2D, structure_texture);    //bind this texture to be active
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, structure.GetWidth(), structure.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, structure.GetBits());

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);   //specify minificaton filtering
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);   //specify magnificaton filtering
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);        //specify texture coordinate treatment
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);        //specify texture coordinate treatment


    glBindTexture(GL_TEXTURE_2D, 0);    //bind default texture to be active
    
    CBitmap wall("wall.bmp");               //read bitmap image
    glGenTextures(1, &wall_texture);          //allocate 1 texture
    glUniform1i(wall_texture, 0);			        //pass texture location to vertex shader
    glBindTexture(GL_TEXTURE_2D, wall_texture);    //bind this texture to be active
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, wall.GetWidth(), wall.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, wall.GetBits());

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);   //specify minificaton filtering
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);   //specify magnificaton filtering
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);        //specify texture coordinate treatment
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);        //specify texture coordinate treatment


    glBindTexture(GL_TEXTURE_2D, 0);    //bind default texture to be active
    
    makeShaders();          //load data of fragment and vertex programs/shaders - compile shaders
    
    glMatrixMode(GL_PROJECTION);       
    glLoadIdentity();                                             //initializes projection matrix with identity
    gluPerspective(60,(float)m_width/(float)m_height,0.1,1000);  //set up projection mode (field of view, aspect ratio, near and far clipping plane)
    
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();                       //initializes modelview matrix with identity
    
    glEnable(GL_CULL_FACE);

}