void display() { glClearColor(0, 0, 1, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); mat4 mv ; const vec3 center(0.0,0.0,0.0) ; if (useGlu) mv = glm::lookAt(eye,center,up) ; else { mv = Transform::lookAt(eye,center,up) ; mv = glm::transpose(mv) ; // accounting for row major } glLoadMatrixf(&mv[0][0]) ; // Set Light and Material properties for the teapot // Lights are transformed by current modelview matrix. // The shader can't do this globally. // So we need to do so manually. transformvec(light_position, light0) ; transformvec(light_position1, light1) ; glUniform4fv(light0posn, 1, light0) ; glUniform4fv(light0color, 1, light_specular) ; glUniform4fv(light1posn, 1, light1) ; glUniform4fv(light1color, 1, light_specular1) ; //glUniform4fv(ambient,1,small) ; //glUniform4fv(diffuse,1,medium) ; glUniform4fv(ambient,1,small) ; glUniform4fv(diffuse,1,small) ; glUniform4fv(specular,1,one) ; glUniform1fv(shininess,1,high) ; glUniform1i(islight,true) ; // Transformations for Teapot, involving translation and scaling mat4 sc(1.0) , tr(1.0) ; sc = Transform::scale(sx,sy,1.0) ; tr = Transform::translate(tx,ty,0.0) ; // Multiply the matrices, accounting for OpenGL and GLM. sc = glm::transpose(sc) ; tr = glm::transpose(tr) ; mat4 transf = mv * tr * sc ; // scale, then translate, then lookat. glLoadMatrixf(&transf[0][0]) ; glutSolidTeapot(2); glutSwapBuffers(); }
void display() { glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glm::mat4 mv; const glm::vec3 center(0.0,0.0,0.0) ; mv = glm::lookAt(eye,center,up) ; glLoadMatrixf(&mv[0][0]) ; glUniform1i(isSin, 1); transformvec(light_position, light0) ; transformvec(light_position1, light1) ; glUniform4fv(light0posn, 1, light0) ; glUniform4fv(light0color, 1, light_specular) ; glUniform4fv(light1posn, 1, light1) ; glUniform4fv(light1color, 1, light_specular1) ; glUniform4fv(ambient,1,small) ; glUniform4fv(diffuse,1,medium) ; glUniform4fv(specular,1,one) ; glUniform1fv(shininess,1,high) ; glUniform1i(islight,true) ; glScalef(0.5, 0.5, 0.5); glPushMatrix(); root->trans = glm::vec3(transx, transy, 0.0); root->GlobalRot = glm::vec3(0.0, rotx, roty); draw(root); glPopMatrix(); if (reachObj != NULL) { glPushMatrix(); glTranslatef(reachObj->trans.x, reachObj->trans.y, reachObj->trans.z); glutSolidSphere(0.5, 100.0, 100.0); glPopMatrix(); inverseK(root); } else { //cout << "NOT DRAWING SPHERE" << endl; } glutSwapBuffers(); }
void display() { glClearColor(0,0,1,0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); mat4 mv; const vec3 center(0.0,0.0,0.0); if (useGlu) mv = glm::lookAt(eye,center,up); else { mv = Transform::lookAt(eye,up); mv = glm::transpose(mv); // accounting for row major } glLoadMatrixf(&mv[0][0]); // Set Light and Material properties for the teapot // Lights are transformed by current modelview matrix. // The shader can't do this globally. // So we need to do so manually. transformvec(light_position,light0); transformvec(light_position1,light1); glUniform4fv(light0posn,1,light0); glUniform4fv(light0color,1,light_specular); glUniform4fv(light1posn,1,light1); glUniform4fv(light1color,1,light_specular1); //glUniform4fv(ambient,1,small); //glUniform4fv(diffuse,1,medium); glUniform4fv(ambient,1,small); glUniform4fv(diffuse,1,small); glUniform4fv(specular,1,one); glUniform1fv(shininess,1,high); glUniform1i(islight,true); glutSolidTeapot(2); glutSwapBuffers(); }
//************************************************************************* void findbestcorr(double **newimage, int ncols, int *bounds, int n, double *origvec,int morigvec,double *transform, int ntransform,int iter) { double *tvec=NULL; double *t=transform+n*ntransform; int boundsvec[2]; double score; double delta=INITDELTA; int i; int precibest=-1; double *newscore=(double *) malloc(2*ntransform*sizeof(double)); int ibestscore; score=cost(newimage,newimage[n],bounds,bounds+2*n, ncols, n)-costd(transform,ncols,ntransform,n,iter); //mexPrintf("score original: %lf pour %d t:%lf costd:%lf\n",score,n,t[0],costd(transform,ncols,ntransform,n,iter)); while(delta>=1) { //mexPrintf("Delta : %f \n",delta); ibestscore=-1; for(i=0;i<ntransform;i++) { if(precibest!=2*i+1) { t[i]+=delta; //mexPrintf("before =="); transformvec(origvec,morigvec,tvec,boundsvec,t,ntransform); //mexPrintf(" ==after t1:%lf b1:%d b2:%d t:%lf\n",tvec[0],boundsvec[0],boundsvec[1],transform[i]); newscore[2*i]=cost(newimage,tvec,bounds,boundsvec, ncols, n)-costd(transform,ncols,ntransform,n,iter); if(newscore[2*i]>score) { score=newscore[2*i]; ibestscore=2*i; } t[i]-=delta; } //mexPrintf("score : %f i:%d bi:%d :\n",newscore[2*i],i,ibestscore); if(precibest!=2*i) { t[i]-=delta; //mexPrintf("before =="); transformvec(origvec,morigvec,tvec,boundsvec,t,ntransform); //mexPrintf(" ==after t1:%lf b1:%d b2:%d t:%lf\n",tvec[0],boundsvec[0],boundsvec[1],transform[i]); newscore[2*i+1]=cost(newimage,tvec,bounds,boundsvec, ncols, n)-costd(transform,ncols,ntransform,n,iter); if(newscore[2*i+1]>score) { score=newscore[2*i+1]; ibestscore=2*i+1; } //mexPrintf("score : %f i:%d bi:%d :\n",newscore[2*i+1],i,ibestscore); t[i]+=delta; } } if(ibestscore==-1) delta=0.5*delta; else{ if(ibestscore%2==0) t[ibestscore/2]+=delta; else t[ibestscore/2]-=delta; } precibest=ibestscore; } //mexPrintf("score final: %lf t:%lf costd:%lf\n",score,t[0],costd(transform,ncols,ntransform,n,iter)); free(newscore); transformvec(origvec, morigvec, tvec, boundsvec, t, ntransform); free(newimage[n]); newimage[n]=tvec; bounds[2*n]=boundsvec[0]; bounds[2*n+1]=boundsvec[1]; }
void display(void) { // clear all pixels glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ; // draw white polygon (square) of unit length centered at the origin // Note that vertices must generally go counterclockwise // Change from the first program, in that I just made it white. // The old OpenGL code of using glBegin... glEnd no longer appears. // The new version uses vertex buffer objects from init. // Does the order of drawing matter? What happens if I draw the ground // after the pillars? I will show this in class glUniform1i(islight,0) ; // Turn off lighting (except on teapot, later) glUniform1i(istex,texturing) ; drawtexture(FLOOR,texNames[0]) ; // Texturing floor // drawobject(FLOOR) ; glUniform1i(istex,0) ; // Other items aren't textured // Now draw several cubes with different transforms, colors // I continue to use the deprecated push-pop and matrix mode // Since it is convenient (or you have to write your own stack). glMatrixMode(GL_MODELVIEW) ; // 1st pillar glPushMatrix() ; glTranslatef(-0.4,-0.4,0.0) ; drawcolor(CUBE, 0) ; glPopMatrix() ; // 2nd pillar glPushMatrix() ; glTranslatef(0.4,-0.4,0.0) ; drawcolor(CUBE, 1) ; glPopMatrix() ; // 3rd pillar glPushMatrix() ; glTranslatef(0.4,0.4,0.0) ; drawcolor(CUBE, 2) ; glPopMatrix() ; // 4th pillar glPushMatrix() ; glTranslatef(-0.4,0.4,0.0) ; drawcolor(CUBE, 3) ; glPopMatrix() ; // Draw the glut teapot // This is using deprecated old-style OpenGL certainly /* New for Demo 3; add lighting effects */ { const GLfloat one[] = {1,1,1,1}; const GLfloat medium[] = {0.5, 0.5, 0.5, 1}; const GLfloat small[] = {0.2, 0.2, 0.2, 1}; const GLfloat high[] = {100} ; const GLfloat zero[] = {0.0, 0.0, 0.0, 1.0} ; const GLfloat light_specular[] = {1, 1, 0, 1}; const GLfloat light_specular1[] = {0, 0.5, 1, 1}; const GLfloat light_direction[] = {0.5, 0, 0, 0}; // Dir light 0 in w const GLfloat light_position1[] = {0, -0.5, 0, 1}; GLfloat light0[4], light1[4] ; // Set Light and Material properties for the teapot // Lights are transformed by current modelview matrix. // The shader can't do this globally. // So we need to do so manually. transformvec(light_direction, light0) ; transformvec(light_position1, light1) ; glUniform3fv(light0dirn, 1, light0) ; glUniform4fv(light0color, 1, light_specular) ; glUniform4fv(light1posn, 1, light1) ; glUniform4fv(light1color, 1, light_specular1) ; // glUniform4fv(light1color, 1, zero) ; glUniform4fv(ambient,1,small) ; glUniform4fv(diffuse,1,medium) ; glUniform4fv(specular,1,one) ; glUniform1fv(shininess,1,high) ; // Enable and Disable everything around the teapot // Generally, we would also need to define normals etc. // But glut already does this for us if (DEMO > 4) glUniform1i(islight,lighting) ; // turn on lighting only for teapot. } // ** NEW ** Put a teapot in the middle that animates glColor3f(0.0,1.0,1.0) ; // Deprecated command to set the color glPushMatrix() ; // I now transform by the teapot translation for animation glTranslatef(teapotloc, 0.0, 0.0) ; // The following two transforms set up and center the teapot // Remember that transforms right-multiply the stack glTranslatef(0.0,0.0,0.1) ; glRotatef(rotamount, 0.0, 0.0, 1.0); glRotatef(90.0,1.0,0.0,0.0) ; glutSolidTeapot(0.15) ; glUniform1i(islight,0) ; // turn off lighting glPopMatrix() ; // Does order of drawing matter? // What happens if I draw the ground after the pillars? // I will show this in class. // drawobject(FLOOR) ; // don't wait! // start processing buffered OpenGL routines glutSwapBuffers() ; glFlush (); }
void shared::display() { glClearColor(0,0,1,0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (wireframe) { glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); } else { glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); } glMatrixMode(GL_MODELVIEW); mat4 mv; const vec3 center(0.0,0.0,0.0); if (useGlu) mv = glm::lookAt(eye,center,up); else { mv = Transform::lookAt(eye,up); mv = glm::transpose(mv); // accounting for row major } glLoadMatrixf(&mv[0][0]); // Set Light and Material properties for the teapot // Lights are transformed by current modelview matrix. // The shader can't do this globally. // So we need to do so manually. transformvec(light_position,light0); transformvec(light_position1,light1); glUniform4fv(light0posn,1,light0); glUniform4fv(light0color,1,light_specular); glUniform4fv(light1posn,1,light1); glUniform4fv(light1color,1,light_specular1); //glUniform4fv(ambient,1,small); //glUniform4fv(diffuse,1,medium); glUniform4fv(ambient,1,small); glUniform4fv(diffuse,1,small); glUniform4fv(specular,1,one); glUniform1fv(shininess,1,high); glUniform1i(islight,true); glUniform1i(isdebug, false); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); if (debug) { glUniform1i(isdebug, true); glEnableClientState(GL_COLOR_ARRAY); std::vector<glm::vec3> colors; std::vector<glm::vec3> vertices; std::vector<glm::vec3> normals; model.debugVerts(&vertices); model.debugVertColors(&colors); model.debugNorms(&normals); glColorPointer(3, GL_FLOAT, 0, &(colors)[0]); glVertexPointer(3, GL_FLOAT, 0, &(vertices)[0]); glNormalPointer(GL_FLOAT, 0, &(normals)[0]); glDrawArrays(GL_TRIANGLES, 0, vertices.size()); glDisableClientState(GL_COLOR_ARRAY); } else { glVertexPointer(3, GL_FLOAT, 0, &(model._vertices)[0]); glNormalPointer(GL_FLOAT, 0, &(model._normals)[0]); glDrawElements(GL_TRIANGLES, model._faces.size(), GL_UNSIGNED_INT, &(model._faces)[0]); } glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glutSwapBuffers(); }