コード例 #1
0
ファイル: main.cpp プロジェクト: andrew-pa/gluk
	void render(float t, float dt) override { 
		dev->push_render_target(intrm);
		s->bind();
		s->set_uniform("view_proj", cam.proj()*cam.view());
		s->set_uniform("camera_position", cam.position());
		s->set_uniform("light_direction", vec3(0.f, 1.f, 0.f));
		
		s->set_uniform("world", mat4(1));
		s->set_uniform("diffuse_color", vec3(0.2f, 0.2f, 0.1f));
		floor->draw();

		s->set_uniform("world", 
			rotate(translate(mat4(1), vec3(-2.f, 2.f, 0.f)), t, vec3(1.f, 0.3f, 0.6f)));
		s->set_uniform("diffuse_color", vec3(0.8f, 0.6f, 0.1f));
		torus->draw();
		
		s->set_uniform("world", translate(mat4(1), vec3(2.f, 1.f, 0.f)));
		s->set_uniform("diffuse_color", vec3(0.3f, 0.6f, 0.8f));
		sphere->draw();

		mat4 ct = translate(mat4(1), vec3(2.f, 1.f, 4.f));
		for(auto& p : car) p->draw(ct, *s);
		
		dev->pop_render_target();
		postprocess_s->bind();
		postprocess_s->set_texture("backbuffer", *intrm, 0);
		postprocess_s->draw(t);
	}	
コード例 #2
0
ファイル: ptxview.cpp プロジェクト: DINKIN/ptexutils
void PtexViewer::render(int selx, int sely)
{
    if (!_shaderProgram) makeShader();

    if (_options.bgColorLight) glClearColor(0.8,0.8,0.8,1);
    else glClearColor(0.0,0.0,0.0,1);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    
    GLint vp[4];  
    glGetIntegerv(GL_VIEWPORT, vp);
    float width = vp[2];
    float height = vp[3];
    float winasp = width/height;
    
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    bool selectMode = selx>=0 && sely>=0;
    
    if (selectMode)
        gluPickMatrix((double)selx,(double)vp[3]-sely,3,3,vp);
    
    if (!_mode3d||_displayFace>=0)
    {
        float sc = _cam.getDistance()/2;
        glOrtho(-sc, sc, -sc/winasp, sc/winasp, -100, 100);

        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glTranslatef(-_cam.getLookAt()[0],-_cam.getLookAt()[1],-_cam.getLookAt()[2]);
    }
    else
    {
        _cam.applyProjectionTransform(winasp, _bounds);

        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        _cam.applyModelViewTransform();
    }
    
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_POLYGON_OFFSET_FILL);
    glPolygonOffset(1.0,1.0);
    glColor4f(1.0, 1.0, 1.0, 1.0);
    glUseProgramObjectARB(_shaderProgram);
    _geometry.draw(_displayFace);
    glUseProgramObjectARB(0);
    if (!selectMode && _options.showGridLines)
    {
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glEnable(GL_LINE_SMOOTH);
        glColor4f(0.0, 0.0, 0.0, 0.25);
        _geometry.draw(_displayFace);
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
        glDisable(GL_BLEND);
        glDisable(GL_LINE_SMOOTH);
    }
    glDisable(GL_POLYGON_OFFSET_FILL);
    glDisable(GL_DEPTH_TEST);
    
    if (selectMode) return;
    
    // Display text information
    char str[64];
    
    if (_options.bgColorLight) glColor3f(0.0, 0.0, 0.0);
    else glColor3f(0.9, 0.9, 0.9);
    
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    
    if (!_options.envMode)
    {
        if (_numFaces==1) strcpy(str, "1 face");
        else sprintf(str,"%i faces",_numFaces);

        renderChars(-0.8,-0.92,GLUT_BITMAP_8_BY_13,str);
        if (_displayFace>=0 && _numFaces!=1)
        {
            sprintf(str,"Face ID: %i",_displayFace);
            renderChars(-0.8,0.92,GLUT_BITMAP_8_BY_13,str);
        }
        if (_numFaces==1)
        {
            int ures = _geometry.getFace(0)->ures;
            int vres = _geometry.getFace(0)->vres;
            sprintf(str,"Res: %i x %i",ures,vres);
            renderChars(-0.8,0.92,GLUT_BITMAP_8_BY_13,str);
        }
        else if (_displayFace>=0)
        {
            int ures = _geometry.getFace(_displayFace)->ures;
            int vres = _geometry.getFace(_displayFace)->vres;
            sprintf(str,"Face Res: %i x %i",ures,vres);
            renderChars(-0.2,0.92,GLUT_BITMAP_8_BY_13,str);
        }
        renderChars(0.25,-0.92,GLUT_BITMAP_8_BY_13,(char*)_typeStr.c_str());
    }
}
コード例 #3
0
void draw_3D_graphics()
{
    static double Px, Py, Pz, roll, pitch, yaw, yawA;
    static int initilization = 0;
    int i;

    static double x = 0.0, dx; // x - an offset for the object
    static double y = 0.0, dy; // z offset controlled by keyboard input
    static double t; // clock time from t0
    static double t0; // initial clock time
    static double T, fps, tp, dt, t_sim;

    // Declare and load x-file mesh object for later
    static mesh m1("car.x");

    // Change scale
    m1.Scale = 0.5;

    // Set initial position for mesh (proper positioning)
    m1.Roll_0 = 1.645;

    // Initialize everything here (once)
    if (!initilization)
    {
        t0 = high_resolution_time();
        tp = 0.0;
        t_sim = 0.0;

        initilization = 1;
    }

    // set_view();
    set_2D_view(50.0, 50.0);

    // draw the axes (red = x, y = green, z = blue)
    draw_XYZ(5.0);  // set axes of 5 m length

    t = high_resolution_time() - t0; // Time since start, as measured by a clock
    T = t - tp; // calculate dt frame or period
    fps = 1 / T;
    tp = t; // save previous time for later


    dt = 0.001; // we can pick a small dt for performance / stability
    while (t_sim < t) {
        sim_step(dt, x, y, yaw);
        t_sim += dt;
    }

    // Use keyboard input to change yaw (upper keys for alphabet)
    if (KEY('Z')) yaw -= 0.001;
    if (KEY('X')) yaw += 0.001;

    // connect graphics parameters with the simulation output
    // NOTE: BECAUSE OF THE WAY WE'VE WRITTEN OUR SIMULATION CODE, THE SIGN NOTATION IS DIFFERENT!
    // HENCE THE NEED FOR YAWA = YAW ACTUAL
    Px = x;
    Py = y;
    Pz = 0;
    roll = 0;
    pitch = 0;
    yawA = -yaw;

    // draw x-file / mesh object
    m1.draw(Px, Py, Pz, yawA, pitch, roll);
}