Example #1
0
/*
    Called whenever no user input given
 */
void glutWidget::update()
{
    m_frame++;
    glutPostRedisplay(); //marks window for redrawing
    setUniform2f(m_program, "center", glutWidget::cx, glutWidget::cy);
    setUniform1f(m_program, "scale", glutWidget::scale);
}
Example #2
0
void StaticEntity::DrawFirstPass()
{
    GLuint shad;
    glm::vec3 minBBoxPoint;
    glm::vec3 distVec;

    if(visible)
    {
        glPushMatrix();
        glMultMatrixf(&matrix[0][0]);
        glScalef(scale,scale,scale);

        for(unsigned int i=0; i<meshObj->mesh.size(); i++)
        {
            if(meshObj->mesh.at(i))
            {
                if(meshObj->material.at(i))
                {
                    //minBBoxPoint = ClosestMeshBBoxPoint(i);
                    //distVec = minBBoxPoint - Camera::getActiveCamera()->pos;
                    //std::cout<<"dist "<<glm::dot(distVec,distVec)<<std::endl;
                    //shad = SceneHandler::shaderLib.GetShaderFromDistance(meshObj->material.at(i)->type,glm::dot(distVec,distVec));
                    shad=SceneHandler::shaderLib.GetShaderFromType(meshObj->material.at(i)->type);

                    glActiveTexture( GL_TEXTURE0 );
                    glBindTexture(GL_TEXTURE_2D, meshObj->material.at(i)->diffuseMap);
                    setUniform1i(shad,0,"diffuseMap");

                    glActiveTexture( GL_TEXTURE1 );
                    glBindTexture(GL_TEXTURE_2D, meshObj->material.at(i)->normalMap);
                    setUniform1i(shad,1,"normalMap");

                    glActiveTexture( GL_TEXTURE2 );
                    glBindTexture(GL_TEXTURE_2D, meshObj->material.at(i)->specularMap);
                    setUniform1i(shad,2,"specularMap");

                    setAttributeTangent(shad, meshObj->mesh.at(i)->tangent, "tangent");

                    setUniform2f(shad,SceneHandler::near,SceneHandler::far,"cameraRange");

                    Camera *cam = Camera::getActiveCamera();
                    setUniform3f(shad,cam->pos.x,cam->pos.y,cam->pos.z,"cameraPos");
                    setUniform3f(shad,cam->dir.x,cam->dir.y,cam->dir.z,"cameraDir");

                    glMaterialfv(GL_FRONT, GL_DIFFUSE, meshObj->material.at(i)->diffuse);
                    glMaterialfv(GL_FRONT, GL_AMBIENT, meshObj->material.at(i)->ambient);
                    glMaterialfv(GL_FRONT, GL_SPECULAR, meshObj->material.at(i)->specular);
                    glMaterialfv(GL_FRONT, GL_SHININESS, meshObj->material.at(i)->shininess);

                    glUseProgram( shad );
                    meshObj->mesh.at(i)->draw();
                    glUseProgram( 0 );
                }
            }
        }
        glPopMatrix();
    }
}
void opengl::ShaderUniforms::setUniform2f(const SCP_string &name, const float x, const float y)
{
	vec2d temp;

	temp.x = x;
	temp.y = y;

	setUniform2f(name, temp);
}
void opengl_uniform_state::setUniform2f(const SCP_string &name, const float x, const float y)
{
	vec2d temp;

	temp.x = x;
	temp.y = y;

	setUniform2f(name, temp);
}
Example #5
0
/*
    Redraws window contents
 */
void glutWidget::render()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);     //clears color and depth bits of framebuffer
    
    
    if(guide)
    {
        glBegin(GL_LINE_LOOP);
        glColor3f(1.0, 0.0, 0.0);
        glVertex2f((0.2+cx)/(scale*0.5), (-0.1+cy)/(scale*0.5));    
        glVertex2f((0.45+cx)/(scale*0.5), (-0.1+cy)/(scale*0.5));
        glVertex2f((0.325+cx)/(scale*0.5), (0.15+cy)/(scale*0.5));
        glEnd();
        
        glBegin(GL_LINE_LOOP);
        glColor3f(1.0, 0.0, 0.0);
        glVertex2f((-0.2+cx)/(scale*0.5), (0.8+cy)/(scale*0.5));    
        glVertex2f((0.0+cx)/(scale*0.5), (0.8+cy)/(scale*0.5));
        glVertex2f((0.0+cx)/(scale*0.5), (1.0+cy)/(scale*0.5));
        glVertex2f((-0.2+cx)/(scale*0.5), (1.0+cy)/(scale*0.5));
        glEnd();
        
        //Circle
        glBegin(GL_LINE_LOOP);
        glColor3f(1.0, 0.0, 0.0);
        for(int i = 0; i < 360; i++)
        {
            glVertex2f((cos((float) i * (3.14159265/180.0)) / 6 + cx + (-1.35)) / (scale*0.5), (sin((float) i * (3.14159265/180.0)) / 6 + cy) / (scale*0.5));
        }
        glEnd();
    }

    glUseProgram(m_program); //Enables fragment shader
    
    //Pass parameters from main program to fragment shader
    setUniform2f(m_program, "center", glutWidget::cx, glutWidget::cy); 
    setUniform1f(m_program, "scale", glutWidget::scale);
    setUniform1i(m_program, "itr", itr);
    setUniform1i(m_program, "color", color);
    
    glBegin(GL_QUADS);
    glTexCoord2f(0, 0);
    glVertex2f(-1, -1);
    glTexCoord2f(1, 0);
    glVertex2f(1, -1);
    glTexCoord2f(1, 1);
    glVertex2f(1, 1);
    glTexCoord2f(0, 1);
    glVertex2f(-1, 1);
    glEnd();
    
    glUseProgram(0); //Disables fragment shader
    
    
    
    glutSwapBuffers();  //swaps front and back buffer for double buffering
}
Example #6
0
void UIShader::begin(){
    if (bEnable){
        checkShaderFile();
        
        ofShader::begin();
        
        for (int i = 0; i < uniforms.size(); i++){
            
            if (uniforms[i]->type == UNIFORM_FLOAT){
                
                if (uniforms[i]->name == "time"){
                    setUniform1f(uniforms[i]->name.c_str(), ofGetElapsedTimef());
                } else {
                    setUniform1f(uniforms[i]->name.c_str(), uniforms[i]->value.x );
                }
               
            } else if (uniforms[i]->type == UNIFORM_VEC2){
                
                if (uniforms[i]->name == "mouse"){
                    setUniform2f(uniforms[i]->name.c_str(), ofGetMouseX(), ofGetMouseY() );
                } else if (uniforms[i]->name == "screen"){
                    setUniform2f(uniforms[i]->name.c_str(), ofGetScreenWidth(), ofGetScreenHeight() );
                } else if (uniforms[i]->name == "windows" || uniforms[i]->name == "resolution" ){
                    setUniform2f(uniforms[i]->name.c_str(), ofGetWidth(), ofGetHeight() );
                } else {
                    setUniform2f(uniforms[i]->name.c_str(), uniforms[i]->value.x, uniforms[i]->value.y );
                }
                
            } else if (uniforms[i]->type == UNIFORM_VEC3){
                
                setUniform3f(uniforms[i]->name.c_str(), uniforms[i]->value.x, uniforms[i]->value.y, uniforms[i]->value.z );
                
            }
        }
    }
}
Example #7
0
//--------------------------------------------------------------
void ofShader::setUniforms(const ofParameterGroup & parameters) const{
	for(int i=0;i<parameters.size();i++){
		if(parameters[i].type()==typeid(ofParameter<int>).name()){
			setUniform1i(parameters[i].getEscapedName(),parameters[i].cast<int>());
		}else if(parameters[i].type()==typeid(ofParameter<float>).name()){
			setUniform1f(parameters[i].getEscapedName(),parameters[i].cast<float>());
		}else if(parameters[i].type()==typeid(ofParameter<ofVec2f>).name()){
			setUniform2f(parameters[i].getEscapedName(),parameters[i].cast<ofVec2f>());
		}else if(parameters[i].type()==typeid(ofParameter<ofVec3f>).name()){
			setUniform3f(parameters[i].getEscapedName(),parameters[i].cast<ofVec3f>());
		}else if(parameters[i].type()==typeid(ofParameter<ofVec4f>).name()){
			setUniform4f(parameters[i].getEscapedName(),parameters[i].cast<ofVec4f>());
		}else if(parameters[i].type()==typeid(ofParameterGroup).name()){
			setUniforms((ofParameterGroup&)parameters[i]);
		}
	}
}
Example #8
0
//--------------------------------------------------------------
void ofShader::setUniform2f(const string & name, const ofVec2f & v) const{
	setUniform2f(name,v.x,v.y);
}
Example #9
0
static void drawGLScene() 
{	
    glClearColor(0, 0, 0, 1);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    float w = glutGet( GLUT_WINDOW_WIDTH );
    float h = glutGet( GLUT_WINDOW_HEIGHT );
    gluPerspective(60, w / h, 0.1, 300);

    glMatrixMode( GL_MODELVIEW );    
    
    //=============================================
    
    glLoadIdentity();
	
	static float time = 0.0;
	time += 0.003;
	
	glUseProgramObjectARB(shaderSky);
	setUniform1f(shaderSky, "time", time);				
	
	glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, 256, 0, GL_BGRA, GL_UNSIGNED_BYTE, colorMapSky);

	
	float skySize=10.0;
	
	glTranslatef(0,0,-5);
	
	glBegin(GL_QUADS);
	glTexCoord2f(0, 0);
	glVertex2f(-skySize, -skySize);
	glTexCoord2f(1, 0);
	glVertex2f(skySize, -skySize);
	glTexCoord2f(1, 1);
	glVertex2f(skySize, skySize);
	glTexCoord2f(0, 1);
	glVertex2f(-skySize, skySize);
	glEnd();
    
	//=============================================
	    
    glLoadIdentity();
    
    glTranslatef(0,0,-2.4);
    glRotatef(xAngle.step(),1,0,0);
    glRotatef(yAngle.step(),0,1,0);
	glRotatef(zAngle.step(),0,0,1);

    
    glUseProgramObjectARB(shaderProgram);
	setUniform2f(shaderProgram, "c", koefReD.step(), koefImD.step());
	setUniform1f(shaderProgram, "bound", movingHighBound.step());

	glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, iterLimit, 0, GL_BGRA, GL_UNSIGNED_BYTE, colorMap);
	
		
	glBegin(GL_QUADS);
	glTexCoord2f(0, 0);
	glVertex2f(-1, -1);
	glTexCoord2f(1, 0);
	glVertex2f(1, -1);
	glTexCoord2f(1, 1);
	glVertex2f(1, 1);
	glTexCoord2f(0, 1);
	glVertex2f(-1, 1);
	glEnd();
	
	//=============================================
	
	glutSwapBuffers();
	
	clrMapData.ColorMapStep();
	constFps.step();
}
Example #10
0
void StaticEntity::Draw()
{
    if(visible)
    {
        Light *nearestLight=SceneHandler::FindNearestLight(matrix[3].x,
                                                           matrix[3].y,
                                                           matrix[3].z);
        if(nearestLight)
            nearestLight->assignTo(0);

        glPushMatrix();
        glMultMatrixf(&matrix[0][0]);
        glScalef(scale,scale,scale);
        glMatrixMode(GL_TEXTURE);
        glActiveTexture(GL_TEXTURE3);

        glPushMatrix();
        glMultMatrixf(&matrix[0][0]);
        glScalef(scale,scale,scale);

        //printf("pos: %f %f %f \n",m_matrix.m_posit.m_x, m_matrix.m_posit.m_y, m_matrix.m_posit.m_z);

        for(unsigned int i=0; i<meshObj->mesh.size(); i++)
        {
            if(meshObj->material.at(i) != NULL)
            {
                glActiveTexture( GL_TEXTURE0 );
                glBindTexture(GL_TEXTURE_2D, meshObj->material.at(i)->diffuseMap);
                setUniform1i(meshObj->material.at(i)->shader,0,"diffuseMap");

                glActiveTexture( GL_TEXTURE1 );
                glBindTexture(GL_TEXTURE_2D, meshObj->material.at(i)->normalMap);
                setUniform1i(meshObj->material.at(i)->shader,1,"normalMap");

                glActiveTexture( GL_TEXTURE2 );
                glBindTexture(GL_TEXTURE_2D, meshObj->material.at(i)->specularMap);
                setUniform1i(meshObj->material.at(i)->shader,2,"specularMap");

                setAttributeTangent(meshObj->material.at(i)->shader, meshObj->mesh.at(i)->tangent, "tangent");

                glMaterialfv(GL_FRONT, GL_DIFFUSE, meshObj->material.at(i)->diffuse);
                glMaterialfv(GL_FRONT, GL_AMBIENT, meshObj->material.at(i)->ambient);
                glMaterialfv(GL_FRONT, GL_SPECULAR, meshObj->material.at(i)->specular);
                glMaterialfv(GL_FRONT, GL_SHININESS, meshObj->material.at(i)->shininess);

                setUniform1f(meshObj->material.at(i)->shader,nearestLight->getRadius(),"lightRadius");

                setUniform2f(meshObj->material.at(i)->shader,(GLfloat)SceneHandler::width,(GLfloat)SceneHandler::height,"bufferSize");

                setUniform1i(meshObj->material.at(i)->shader,SceneHandler::width,"screenWidth");
                setUniform1i(meshObj->material.at(i)->shader,SceneHandler::height,"screenHeight");

                glUseProgram( meshObj->material.at(i)->shader );

            }
            if(meshObj->mesh.at(i))
            {
                meshObj->mesh.at(i)->draw();
            }
        }

        glUseProgram( 0 );

        glPopMatrix();
        glMatrixMode(GL_MODELVIEW);
        glPopMatrix();

        glBindTexture(GL_TEXTURE_2D, 0);
    }
}
 void setUniform(const fvec2& value)  { setUniform2f(1, value.ptr()); }
 void setUniform(int count, const fvec2* value)  { setUniform2f(count, value->ptr()); }
Example #13
0
void begin()
{
    

    // old-BATB didn't like to be initialized more than once :(
    // hence, ignore re-init for specified parts, and continue with previous state
    static bool empty = true;
    
    // clear exit, making possible to start over again
    //do_exit = false;

        // copied from old::main:
        //MainWindow::winPosX = 100;
        //MainWindow::winPosY = 100;
        //MainWindow::winWidth = 640;
        //MainWindow::winHeight = 480;

        // init glut
        //glutInitWindowPosition(MainWindow::winPosX, MainWindow::winPosY);
        //glutInitWindowSize    (MainWindow::winWidth, MainWindow::winHeight);
        //glutInit              (&argc, argv);
        //glutInitDisplayMode   (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
        //MainWindow::main_window = glutCreateWindow("Beat About the Bush");
        MainWindow::enableDisplayFunc();

        // implemented as GLFW:

        GLFWwindow* win = glfwGetCurrentContext();
        glfwSetKeyCallback( win, MainWindow::glfwKey  );                  //glutKeyboardFunc      (MainWindow::keyDownFn); 
                                                                                          //glutSpecialFunc       (MainWindow::specialDownFn);
                                                                                          ////glutKeyboardUpFunc    (MainWindow::keyUpFn);
                                                                                          ////glutSpecialUpFunc     (MainWindow::specialUpFn);
        glfwSetCursorPosCallback( win, MainWindow::glfwCursorPos );       //glutMouseFunc         (MainWindow::mousefn); 
        glfwSetMouseButtonCallback( win, MainWindow::glfwMouseButton);    //glutMotionFunc        (MainWindow::motionfn);
                                                                                          
        glfwSetWindowSizeCallback( win, MainWindow::glfwWindowSize );     //glutReshapeFunc       (MainWindow::reshapefn);
        glfwSetWindowFocusCallback( win, MainWindow::glfwWindowFocus );   //glutVisibilityFunc    (MainWindow::visibility);
        
        
        
        
    if ( empty )
    {

        // init plib, with no GLUT-binding!
        puInitOLD();

        puSetDefaultStyle        ( PUSTYLE_SMALL_SHADED );
        puSetDefaultColourScheme ( 0.3f, 0.4f, 0.6f, 1.0f);

        // Initialize the "OpenGL Extension Wrangler" library
        //glewInit();
    }

        mainWindow.initLights();

    if ( empty )
    {
        mainWindow.init();
        printVersions();

        // Make sure that OpenGL 2.0 is supported by the driver
        int gl_major, gl_minor;
        getGlVersion(&gl_major, &gl_minor);
        printf("GL_VERSION major=%d minor=%d\n", gl_major, gl_minor);

        if (gl_major < 2)
        {
            printf("GL_VERSION major=%d minor=%d\n", gl_major, gl_minor);
            printf("Support for OpenGL 2.0 is required for this demo...exiting\n");
            //exit(1);
            old::exit(1);
            return;
        }

        // init shaders
        GLchar *dayVSSource, *dayFSSource;
        readShaderSource( old::file("shader/day").c_str(), &dayVSSource, &dayFSSource);
        dayShader = installShaders(dayVSSource, dayFSSource);
        float forestGreen[] = {34.0/255, 139.0/255, 34.0/255};
        //float auburn[] = {113.0/255, 47.0/255, 38.0/255};
        float grey[] = {0.5, 0.5, 0.5};
        //float sepia[] = {112.0/255, 66.0/255, 20.0/255};

        setUniform3f(dayShader, "GrassColor", forestGreen[0], forestGreen[1], forestGreen[2]);
        setUniform3f(dayShader, "RockColor", grey[0], grey[1], grey[2]);
        //setUniform3f(dayShader, "DirtColor", sepia[0], sepia[1], sepia[2]);
        //setUniform4f(dayShader, "LightPos", 0.0, 0.0, 100.0, 1.0);
        setUniform1f(dayShader, "Scale", 1.0);
        setUniform1f(dayShader, "TerrainHigh", 0.1);
        setUniform1f(dayShader, "TerrainLow", 0.1);
        setUniform1i(dayShader, "Trees", 0); // sampler
        setUniform1i(dayShader, "AltGrad", 1); // sampler
        setUniform1i(dayShader, "Noise", 2); // sampler

        GLchar *nightVSSource, *nightFSSource;
        readShaderSource( old::file("shader/night3").c_str(), &nightVSSource, &nightFSSource);
        nightShader = installShaders(nightVSSource, nightFSSource);
        setUniform3f(nightShader, "BrickColor", 1.0, 0.3, 0.2);
        setUniform3f(nightShader, "MortarColor", 0.85, 0.86, 0.84);
        setUniform2f(nightShader, "BrickSize", 0.30, 0.15);
        setUniform2f(nightShader, "BrickPct", 0.90, 0.85);
        setUniform1i(nightShader, "numEnabledLights", 2);

        setUniform3f(nightShader, "GrassColor", forestGreen[0], forestGreen[1], forestGreen[2]);
        setUniform3f(nightShader, "RockColor", grey[0], grey[1], grey[2]);
        setUniform1f(nightShader, "Scale", 1.0);
        setUniform1f(nightShader, "TerrainHigh", 0.1);
        setUniform1f(nightShader, "TerrainLow", 0.1);
        setUniform1i(nightShader, "Trees", 0); // sampler
        setUniform1i(nightShader, "AltGrad", 1); // sampler
        setUniform1i(nightShader, "Noise", 2); // sampler

        GLchar *nightTreeVS, *nightTreeFS;
        readShaderSource( old::file("shader/nightTree").c_str(), &nightTreeVS, &nightTreeFS);
        nightTrees = installShaders(nightTreeVS, nightTreeFS);
        setUniform1i(nightTrees, "Trees", 0); // sampler

        // BUGFIX:
        free( dayVSSource );
        free( dayFSSource );
        free( nightVSSource );
        free( nightFSSource );
        free( nightTreeVS );
        free( nightTreeFS );
    }

        // enter main loop
        //if (dayShader && nightShader)
        //    glutMainLoop();

        //return 0;

    empty = false;

}