Jump to content
  • Advertisement

pkiskool

Member
  • Content Count

    46
  • Joined

  • Last visited

Community Reputation

115 Neutral

About pkiskool

  • Rank
    Member
  1. pkiskool

    Using glutBitmapCharacter

    Thanks. I'll look into that.
  2. pkiskool

    Using glutBitmapCharacter

    Yes - I am using c++. and sorry, I have no clue what std::stringstream is about and how to use it... All I know is: double f = 3.1452; cout << setprecision (2) << f; I suppose this is irrelevant to std::stringstream... Please help.
  3. pkiskool

    Using glutBitmapCharacter

    Thank you. I was able to display decimals by simply changing %d to %f. But now it is displaying down to 0.00000n, which is too many. I know how to set the precision when doing couts but not sure what to do for this case. It would be great if you could give me a guide. Thanks.
  4. Hi everyone, I have a 'timer' in my program which I display it on the graphics using glutBitmapCharacter. void render_text(float x, float y, char* s) { glRasterPos2f(x,y); for ( unsigned int i=0; i < strlen( s ); i++ ) glutBitmapCharacter(GLUT_BITMAP_9_BY_15,s); } Above is the function I use, and I call it like below: snprintf(text_buffer, 40, "Fill Time: %d Sec", filltime ); glColor3f(1.0f, 1.0f, 1.0f); render_text( 10-Gc, 5+Gc, text_buffer ); However, this works fine with integers, but when I try to use double or float (sometimes my filltime gets down to decimal numbers), this craps out. I need it to display down to 2nd decimals. (i.e. 0.02 sec, 0.03 sec etc) Not sure what to do at this point, I'm a fairly newbew to this... Please help!
  5. pkiskool

    [Newb] Text file writing question

    Just wanted to let you all know that it is working great! Thanks again!
  6. pkiskool

    [Newb] Text file writing question

    Hey guys, Thanks for the replies! I was away for Easter and I just got around checking this for the first time. Both of you have shown great ideas and I can't wait to try them out! (not at work right now!) Great help! If I have further questions, I'll be posting it here so please check back time to time! Thanks Zahlman and CukyDoh!
  7. Hi, I'm a relative newbie to the development aspect of the coding. I've got a real newbie question that some of you might find offensive to be even posted as a thread on this website, so please go easy on me. I'm running a visual simulation of fluid flow in a cavity. It also calculates the pressure distribution at each time steps, and then prints out the pressure solution as a .txt file. But right now, the solution file gets written over every time, thus I end up with only one solution file at the end of simulation - let's say after 100 seconds. Ideally I would want to have 100 different .txt file at each time step showing different solutions. Here's how I write the txt file right now: //Writing solution (pressure) to txt ofstream solfile ("solution.txt"); if (solfile.is_open()) { solfile << "Solution:" <<"\n"; for (j = 0; j <= n-1; j++) { for (i=1; i<=m; i++) { if (type[j*m+i]==0) { solfile << setw(10) << setprecision (3) << pres[j*m+i]; } else if (type[j*m+i]==3) { solfile << setw(10) << " "; } else if (type[j*m+i]==2) { job2+=1; solfile << setw(10) << setprecision (3) << x[job2]; } else if (type[j*m+i]==1) { solfile << setw(10) << setprecision (3) << pres[j*m+i]; } else if (type[j*m+i]==4) { solfile << setw(10) << setprecision (3) << "#"; //used to be just 'i' } } solfile << "\n"; solfile << "\n"; } } Is there a way to update ofstream solfile ("solution.txt"); at every time step so that it starts saving files such as; solution1.txt, solution2.txt, solution3.txt etc etc? Thank you all for taking your time to read and help.
  8. I'm developing a software for my master's degree, where I basically simulate a 2D fluid flow in a cavity. I have a question regarding the graphics side of my program, which I need to improve the fps of my software using the Display List. I currently draw things in the ordinary slow way, but someone has told me that DL is a good way to improve fps and remove some lags. My program is very choppy at the moment and I really need to improve this... but I'm not too sure how to implement the DL. I've tried following a tutorial but failed miserably. Someone please give me a help... Here is source code for the GRAPHICS section (I won't include the math section). //HEADER FILES #include "glut.h" #include <iostream> #include <iomanip> #include <fstream> #include <cstdlib> #include <cmath> #include <math.h> #include <string> #include <stdlib.h> #define TINY 1.0e-20; #define NRANSI #define GL_PI 3.1415f #include "nrutil.h" //NR #include "nrutil.cpp" //NR #include "ludcmp.h" //NR #include "lubksb.h" //NR #include "matcalc2.h" #include "matcalc3.h" #include "front.h" // Rotation amounts static GLdouble xRot = 0.0f; static GLdouble yRot = 0.0f; static GLdouble zRot = 0.0f; static GLdouble eyeX = 0.0f; static GLdouble eyeY = -1.0f; static GLdouble eyeZ = 2500.0f; static GLdouble centerX = 0.0f; static GLdouble centerY = 0.0f; static GLdouble centerZ = 0.0f; static GLdouble upX = 0.0f; static GLdouble upY = 0.0f; static GLdouble upZ = 1.0f; static GLdouble scale = 1.0f; bool GeometryFlag; bool ZoomInFlag; bool ZoomOutFlag; bool NumFlag; bool LegendFlag=true; int numb=0; GLdouble y, x; double gridspace = 12.0f; unsigned int now, last; #pragma warning( disable : 4996 ) //////////////////////////////////////////// // Text rendering function// ////////////////////////////////////////// void render_text(float x, float y, char* s) { glRasterPos2f(x,y); for ( unsigned int i=0; i < strlen( s ); i++ ) glutBitmapCharacter(GLUT_BITMAP_9_BY_15,s); } /////////////////////////////////////////////////////////// // Setup the rendering state ////////////////////////////////////////////////////////// // Called to draw scene void RenderScene(void) { /*now = GetTickCount(); //comment THIS (only // parts) out TO GO MANAUL//////////////////////////////////////////////////////////////////////////////// if (now-last>100){ //THE NUMBER HERE CONTROLS THE SPEED - 1000 IS 1 SECOND last = now; // front(); // if (SolutionFlag==true) {// matcalc3(); // SolutionFlag=false; // } // } //*/ int i, j; int Gc = gridspace*(n-1)/2, Gt = (gridspace * n)/2-(gridspace/2); double k; GLdouble fCurrSize; // Save current size // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT); // Save matrix state and do the rotation glPushMatrix(); glRotatef(xRot, 1.0f, 0.0f, 0.0f); glRotatef(yRot, 0.0f, 1.0f, 0.0f); glRotatef(zRot, 0.0f, 0.0f, 1.0f); char text_buffer[100]; // should be big enough _snprintf(text_buffer, 40, "FILL TIME %d SEC", filltime ); glColor3f(1.0f, 1.0f, 1.0f); render_text( 50-Gc, 5+Gc, text_buffer ); // Set up x lines for(y = - Gc; y <= (gridspace * n)/2-(gridspace/2); y += gridspace) { // Set the line width glLineWidth(2); // Draw the upper line glBegin(GL_LINES); glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f( - Gc, y, 0); glVertex3f(- Gc + gridspace*(m-1), y, 0); // Draw the lower line glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f( - Gc, y, - 5); glVertex3f(- Gc + gridspace*(m-1), y, - 5); } // Set up y lines for(x = - Gc; x <= - Gc + gridspace*(m-1); x += gridspace) { // Draw the upper line glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f(x, - Gc, 0); glVertex3f(x, Gc, 0); // Draw the lower line glBegin(GL_LINES); glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f(x, - Gc, -5); glVertex3f(x, Gc, -5); } //1D case if (n==1) { for(x = - Gc; x <= - Gc + gridspace*(m-1); x += gridspace) { // Set the line width // Draw the upper line glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f(x, - ((gridspace * (n+1)*0.3)/2-(gridspace/2)), 0); glVertex3f(x, ((gridspace * (n+1)*0.3)/2-(gridspace/2)), 0); // Draw the lower line glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f(x, - ((gridspace * (n+1)*0.3)/2-(gridspace/2)), -5); glVertex3f(x, ((gridspace * (n+1)*0.3)/2-(gridspace/2)), -5); } } // Set up z lines (4 corners) - thickness to the plate glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f( - Gc, - Gc, 0); glVertex3f( - Gc, - Gc, -5); glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f( - Gc, (gridspace * n)/2-(gridspace/2), 0); glVertex3f( - Gc, (gridspace * n)/2-(gridspace/2), -5); glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f(- Gc + gridspace*(m-1), - Gc, 0); glVertex3f(- Gc + gridspace*(m-1), - Gc, -5); glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f(- Gc + gridspace*(m-1), (gridspace * n)/2-(gridspace/2), 0); glVertex3f(- Gc + gridspace*(m-1), (gridspace * n)/2-(gridspace/2), -5); glEnd(); //Draw circle (last wetted node) for (i=0; i<=n-1; i++) { for (j=1; j<=m; j++) { if (type[i*m+j]==1) { //'o' - display with a hollow white circle /*glBegin(GL_LINE_LOOP); //De-bug mode for flow fronts glColor3f(0.000f, 0.000f, 1.000f); for (k=0; k<=360; k+=15) { glVertex2f( (-(gridspace * n)/2-(gridspace/2)+j*gridspace) + sin(k*0.0174) * 3.5, ( ((gridspace * n)/2-(gridspace/2) - (i*gridspace)) + cos(k*0.0174) * 3.5) ); }*/ glBegin(GL_TRIANGLE_FAN); glColor3f(0.000f, 0.000f, 1.000f); for (k=0; k<=360; k+=15) { glVertex2f( (-(gridspace * n)/2-(gridspace/2)+j*gridspace) + sin(k*0.0174) * 3.5, ( ((gridspace * n)/2-(gridspace/2) - (i*gridspace)) + cos(k*0.0174) * 3.5) ); } glEnd(); } else if (type[i*m+j]==0) { //'i' - display with a red circle glBegin(GL_TRIANGLE_FAN); glColor3f(1.0f, 0.0f, 0.0f); //Red for (k=0; k<=360; k+=15) { glVertex2f( (-(gridspace * n)/2-(gridspace/2)+j*gridspace) + sin(k*0.0174) * 3.5, ( ((gridspace * n)/2-(gridspace/2) - (i*gridspace)) + cos(k*0.0174) * 3.5) ); } glEnd(); } else if (type[i*m+j]==2) { //'x' - display with a white filled circle glBegin(GL_TRIANGLE_FAN); //COLOR CODE if (pres[i*m+j] >= 0 && pres[i*m+j] < inpres*1000/12*1) glColor3f(0.000f, 0.000f, 1.000f); //Slate Blue if (pres[i*m+j] >= inpres*1000/12*1 && pres[i*m+j] < inpres*1000/12*2) glColor3f(0.000f, 0.5000f, 1.000f); //Sky Blue if (pres[i*m+j] >= inpres*1000/12*2 && pres[i*m+j] < inpres*1000/12*3) glColor3f(0.000f, 0.800f, 1.000f); //Medium Torquoise if (pres[i*m+j] >= inpres*1000/12*3 && pres[i*m+j] < inpres*1000/12*4) glColor3f(0.000f, 1.000f, 1.000f); //Aquamarine if (pres[i*m+j] >= inpres*1000/12*4 && pres[i*m+j] < inpres*1000/12*5) glColor3f(0.000f, 1.000f, 0.600f); //Spring Green if (pres[i*m+j] >= inpres*1000/12*5 && pres[i*m+j] < inpres*1000/12*6) glColor3f(0.000f, 1.000f, 0.000f); //Lime Green if (pres[i*m+j] >= inpres*1000/12*6 && pres[i*m+j] < inpres*1000/12*7) glColor3f(0.500f, 0.900f, 0.0f); //Green if (pres[i*m+j] >= inpres*1000/12*7 && pres[i*m+j] < inpres*1000/12*8) glColor3f(0.800f, 0.900f, 0.000f); //Medium Spring Green if (pres[i*m+j] >= inpres*1000/12*8 && pres[i*m+j] < inpres*1000/12*9) glColor3f(1.000f, 1.000f, 0.000f); if (pres[i*m+j] >= inpres*1000/12*9 && pres[i*m+j] < inpres*1000/12*10) glColor3f(1.000f, 0.800f, 0.000f); //Coral if (pres[i*m+j] >= inpres*1000/12*10 && pres[i*m+j] < inpres*1000/12*11) glColor3f(1.000f, 0.500f, 0.000f); if (pres[i*m+j] >= inpres*1000/12*11 && pres[i*m+j] < inpres*1000/12*12) glColor3f(1.0f, 0.0f, 0.0f); //changed to Red for (k=0; k<=360; k+=15) { glVertex2f( (-(gridspace * n)/2-(gridspace/2)+j*gridspace) + sin(k*0.0174) * 3.5, ( ((gridspace * n)/2-(gridspace/2) - (i*gridspace)) + cos(k*0.0174) * 3.5) ); } glEnd(); } else if (type[i*m+j]==4) { //'+' - display with a white cube glColor3f(0.9882f, 0.9882f, 0.9882f); glRectf((-(gridspace * n)/2-(gridspace/2)+j*gridspace) - 4, ( ((gridspace * n)/2-(gridspace/2) - i*gridspace) ) -4, (-(gridspace * n)/2-(gridspace/2)+j*gridspace) + 4, ( ((gridspace * n)/2-(gridspace/2) - i*gridspace) ) +4); glEnd(); } }//end of for j }//end of for i for (i=0; i<=n-1; i++) { for (j=1; j<=m; j++) { //Flow front display if (xseg[i*m+j] <= 0.999 && xseg[i*m+j] >= -0.01) { //xseg has a value if (type[i*m+j]==3 && (type[i*m+j+1]==1 || type[i*m+j+1]==0 || type[i*m+j+1]==2)) { //glBegin(GL_LINE_LOOP); glBegin(GL_TRIANGLE_FAN); glColor3f(0.000f, 0.000f, 1.000f); //Blue for (k=0; k<=360; k+=15) { glVertex2f( -(gridspace * n)/2-(gridspace/2)+(j+1)*gridspace - (gridspace*xseg[i*m+j]) + sin(k*0.0174) * 3.5, ((gridspace * n)/2 - (gridspace/2) - i*gridspace) + cos(k*0.0174) * 3.5); } glEnd(); } else if ((type[i*m+j]==1 || type[i*m+j]==0 || type[i*m+j]==2) && type[i*m+j+1]==3) { //glBegin(GL_LINE_LOOP); glBegin(GL_TRIANGLE_FAN); glColor3f(0.000f, 0.000f, 1.000f); //Blue for (k=0; k<=360; k+=15) { glVertex2f( -(gridspace * n)/2-(gridspace/2)+j*gridspace + (gridspace*xseg[i*m+j]) + sin(k*0.0174) * 3.5, ((gridspace * n)/2-(gridspace/2) - i*gridspace) + cos(k*0.0174) * 3.5); } glEnd(); } } }//end of for j }//end of for i for (i=0; i<=n-2; i++) { for (j=1; j<=m; j++) { if (yseg[i*m+j] <= 0.999 && yseg[i*m+j] >= -0.01) { //yseg has a value if (type[i*m+j]==3 && (type[i*m+j+m]==1 || type[i*m+j+m]==0 || type[i*m+j+m]==2)) { glBegin(GL_TRIANGLE_FAN); glColor3f(0.000f, 0.000f, 1.000f); //Blue for (k=0; k<=360; k+=15) { glVertex2f( (-(gridspace * n)/2-(gridspace/2)+j*gridspace) + sin(k*0.0174) * 3.5 , ((gridspace * n)/2-(gridspace/2) - (i+1)*gridspace) + (gridspace*yseg[i*m+j]) + cos(k*0.0174) * 3.5); } glEnd(); } else if ( (type[i*m+j]==1 || type[i*m+j]==0 || type[i*m+j]==2) && type[i*m+j+m]==3) { //glBegin(GL_LINE_LOOP); glBegin(GL_TRIANGLE_FAN); glColor3f(0.000f, 0.000f, 1.000f); //Blue for (k=0; k<=360; k+=15) { glVertex2f( (-(gridspace * n)/2-(gridspace/2)+j*gridspace) + sin(k*0.0174) * 3.5, ((gridspace * n)/2-(gridspace/2) - i*gridspace) - (gridspace * yseg[i*m+j]) + cos(k*0.0174) * 3.5); } glEnd(); } } } } if (NumFlag == true) { //Set up node number fonts int nodecount=0; for (y = (gridspace * n)/2-(gridspace/2); y >= - Gc; y -= gridspace) { for (x = - Gc ; x <= - Gc + gridspace*(m-1); x += gridspace) { nodecount += 1; glColor3f(1.0f, 1.0f, 1.0f); _snprintf(text_buffer, 40, "%d", nodecount ); render_text( x-2.5,y, text_buffer ); } } } if (LegendFlag == true) { int in, la, dv; glBegin(GL_LINES); glLineWidth(0.5); glColor3f(1.0f, 1.0f, 1.0f); for (la = 8; la <= 104; la += 8) { glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - la); glVertex2f(- Gc - 43, (gridspace * n)/2-(gridspace/2) - la); } glEnd(); in = inpres * 1000; for (dv = 12, la = 8; dv >= 0 && la <= 104; dv --, la += 8) { _snprintf(text_buffer, 40, "%d", in * dv/12); render_text( - Gc - 39, (gridspace * n)/2-(gridspace/2) - la, text_buffer ); } glBegin(GL_QUADS); glColor3f(1.000f, 0.000f, 0.000f); //Red glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 8); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 8); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 16); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 16); glColor3f(1.000f, 0.500f, 0.000f); //Orange Red glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 16); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 16); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 24); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 24); glColor3f(1.000f, 0.800f, 0.000f); //Coral glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 24); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 24); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 32); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 32); glColor3f(1.000f, 1.000f, 0.000f); //Yellow glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 32); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 32); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 40); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 40); glColor3f(0.800f, 0.900f, 0.000); //Medium Spring Green glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 40); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 40); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 48); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 48); glColor3f(0.5f, 0.9f, 0.0f); //Green glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 48); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 48); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 56); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 56); glColor3f(0.000f, 1.000f, 0.000f); //Lime Green glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 56); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 56); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 64); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 64); glColor3f(0.000f, 1.000f, 0.498f); //Spring Green glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 64); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 64); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 72); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 72); glColor3f(0.0f, 1.0f, 1.0f); //Aquamarine glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 72); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 72); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 80); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 80); glColor3f(0.0f, 0.8f, 1.0f); //Medium Torquoise glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 80); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 80); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 88); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 88); glColor3f(0.0f, 0.5f, 1.0f); //Sky Blue glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 88); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 88); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 96); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 96); glColor3f(0.0f, 0.0f, 1.0f); //Slate Blue glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 96); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 96); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 104); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 104); glEnd(); _snprintf(text_buffer, 40, "UNIT: Pa"); glColor3f(1.000f, 1.000f, 1.000f); render_text( - Gc - 50, (gridspace * n)/2-(gridspace/2) - 116, text_buffer ); } // Restore transformations glPopMatrix(); // Flush drawing commands glutSwapBuffers(); glutPostRedisplay(); //change buffer, 2 buffers enables smooth drawing in one go glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(eyeX,eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ); } void SetupRC(void) { // Black background glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); } void ChangeSize(int w, int h) { GLfloat fAspect; // Prevent a divide by zero if(h == 0) h = 1; // Set Viewport to window dimensions glViewport(0, 0, w, h); fAspect = (GLfloat)w/(GLfloat)h; // Reset coordinate system glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Produce the perspective projection gluPerspective(5.0f, fAspect, 1.0, 6000.0); } void OtherKeys(unsigned char key, int z, int a) { if(key == 't') { // 't' starts the flow during manual mode if (GeometryFlag==false) GeometryFlag=true; else if (GeometryFlag==true) GeometryFlag=false; } if (GeometryFlag==true) { front(); } if (SolutionFlag==true) { matcalc3(); SolutionFlag=false; } } void SpecialKeys(int key, int x, int y) { if(key == GLUT_KEY_UP) { //rotates about x xRot -= 5.0f; } if(key == GLUT_KEY_DOWN) { xRot += 5.0f; } if(key == GLUT_KEY_LEFT) { //rotates about y yRot -= 5.0f; } if(key == GLUT_KEY_RIGHT) { yRot += 5.0f; } if(key == GLUT_KEY_HOME) { //rotates about z zRot -= 5.0f; } if(key == GLUT_KEY_END) { zRot += 5.0f; } if(key == GLUT_KEY_F1) { //Zoom in with F1 eyeZ += 25; } if(key == GLUT_KEY_F2) { //Zoom out with F2 eyeZ -= 25; } if(key == GLUT_KEY_F3) { //Toggle node numbers with F3 if (NumFlag==false) NumFlag=true; else if (NumFlag==true) NumFlag=false; } if (key == GLUT_KEY_F4) { //Toggle legend on and off with F4 if (LegendFlag==false) LegendFlag=true; else if (LegendFlag==true) LegendFlag=false; } if(key == GLUT_KEY_F5) { // Pause with F5 cout << "Paused." << "\n"; system ("pause"); } if (key == GLUT_KEY_F12) { //Increase time step with F12 t += 1; } if (key == GLUT_KEY_F11) { //Decrease time step with F11 t += -1; } if(key == GLUT_KEY_PAGE_UP) { //pans along x-positive eyeX -= 5.0f; centerX -= 5.0f; } if(key == GLUT_KEY_INSERT) { //pans along x-negative eyeX += 5.0f; centerX += 5.0f; } if(zRot > 356.0f) zRot = 0.0f; if(zRot < -1.0f) zRot = 355.0f; if(xRot > 356.0f) xRot = 0.0f; if(xRot < -1.0f) xRot = 355.0f; if(yRot > 356.0f) yRot = 0.0f; if(yRot < -1.0f) yRot = 355.0f; } int main (int argc, char **argv) { //last = GetTickCount(); //Comment THIS out TO GO MANUAL///////////////////////////////////////////// cout << "Enter distance between the nodes (m): "; cin >> del_x; cout << "\n"; cout << "Enter time step (s): "; cin >> t; cout << "\n"; cout << "Enter viscosity of resin: "; cin >> visco; cout << "\n"; cout << "Enter porosity of fibre: "; cin >> poro; cout << "\n"; matcalc2(); //Draw after each time step glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(1152,864); glutCreateWindow("Simulation of VARTM Resin Impregnation Process"); glutReshapeFunc(ChangeSize); glutSpecialFunc(SpecialKeys); glutDisplayFunc(RenderScene); glutKeyboardFunc(OtherKeys) SetupRC(); glutMainLoop(); } Thanks!
  9. pkiskool

    C++ openGL : Lag issue

    Well ... front() is another file which determines the speed of these circles... But - don't worry about the timer thing anymore. The time now runs because I simply moved around the display list. glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(1152,864); glutCreateWindow("Simulation of VARTM Resin Impregnation Process"); glutReshapeFunc(ChangeSize); glutSpecialFunc(SpecialKeys); glutKeyboardFunc(OtherKeys); glNewList( circle, GL_COMPILE ); glBegin(GL_TRIANGLE_FAN); for (Rd=0; Rd<=360; Rd+=15) glVertex2f( sin(Rd*0.0174) * 3.5, cos(Rd*0.0174) * 3.5 ); glEnd(); glEndList(); glutDisplayFunc(RenderScene); SetupRC(); glutMainLoop(); The problem of no circles displaying still exists however...
  10. pkiskool

    C++ openGL : Lag issue

    OK - so the reason why there's only a few circles showing, is because I forgot to edit one of the section (GL_TRIANGLE_FAN is still being used there). So when I update that part with display list, there is essentially no circles. Only lines and text are rendered - and the rendering is done only once. Initially, when I press 't', this would trigger the timer and I was able to see the flow. But pressing 't' now doesn't do anything - the timer stays still.
  11. pkiskool

    C++ openGL : Lag issue

    Ooops I sourced the wrong code - that one is the version W/O the display list. Here is the correct one. //HEADER FILES #include "glut.h" #include <iostream> #include <iomanip> #include <fstream> #include <cstdlib> #include <cmath> #include <math.h> #include <string> #include <stdlib.h> #define TINY 1.0e-20; #define NRANSI #define GL_PI 3.1415f #include "nrutil.h" //NR #include "nrutil.cpp" //NR #include "ludcmp.h" //NR #include "lubksb.h" //NR #include "matcalc2.h" #include "matcalc3.h" #include "front.h" // Rotation amounts static GLdouble xRot = 0.0f; static GLdouble yRot = 0.0f; static GLdouble zRot = 0.0f; static GLdouble eyeX = 0.0f; static GLdouble eyeY = -1.0f; static GLdouble eyeZ = 2500.0f; static GLdouble centerX = 0.0f; static GLdouble centerY = 0.0f; static GLdouble centerZ = 0.0f; static GLdouble upX = 0.0f; static GLdouble upY = 0.0f; static GLdouble upZ = 1.0f; static GLdouble scale = 1.0f; bool GeometryFlag; bool ZoomInFlag; bool ZoomOutFlag; bool NumFlag; bool LegendFlag=true; int numb=0; GLdouble y, x; double gridspace = 12.0f; unsigned int now, last; // this can be a global GLuint circle; #pragma warning( disable : 4996 ) //////////////////////////////////////////// // Text rendering function// ////////////////////////////////////////// void render_text(float x, float y, char* s) { glRasterPos2f(x,y); for ( unsigned int i=0; i < strlen( s ); i++ ) glutBitmapCharacter(GLUT_BITMAP_9_BY_15,s); } /////////////////////////////////////////////////////////// // Setup the rendering state ////////////////////////////////////////////////////////// // Called to draw scene void RenderScene(void) { /*now = GetTickCount(); //comment THIS (only // parts) out TO GO MANAUL//////////////////////////////////////////////////////////////////////////////// if (now-last>100){ //THE NUMBER HERE CONTROLS THE SPEED - 1000 IS 1 SECOND last = now; // front(); // if (SolutionFlag==true) {// matcalc3(); // SolutionFlag=false; // } // } //*/ int i, j; int Gc = gridspace*(n-1)/2, Gt = (gridspace * n)/2-(gridspace/2); double k; GLdouble fCurrSize; // Save current size // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT); // Save matrix state and do the rotation glPushMatrix(); glRotatef(xRot, 1.0f, 0.0f, 0.0f); glRotatef(yRot, 0.0f, 1.0f, 0.0f); glRotatef(zRot, 0.0f, 0.0f, 1.0f); char text_buffer[100]; // should be big enough _snprintf(text_buffer, 40, "FILL TIME %d SEC", filltime ); glColor3f(1.0f, 1.0f, 1.0f); render_text( 50-Gc, 5+Gc, text_buffer ); // Set up x lines for(y = - Gc; y <= (gridspace * n)/2-(gridspace/2); y += gridspace) { // Set the line width glLineWidth(2); // Draw the upper line glBegin(GL_LINES); glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f( - Gc, y, 0); glVertex3f(- Gc + gridspace*(m-1), y, 0); // Draw the lower line glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f( - Gc, y, - 5); glVertex3f(- Gc + gridspace*(m-1), y, - 5); } // Set up y lines for(x = - Gc; x <= - Gc + gridspace*(m-1); x += gridspace) { // Draw the upper line glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f(x, - Gc, 0); glVertex3f(x, Gc, 0); // Draw the lower line glBegin(GL_LINES); glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f(x, - Gc, -5); glVertex3f(x, Gc, -5); } //1D case if (n==1) { for(x = - Gc; x <= - Gc + gridspace*(m-1); x += gridspace) { // Set the line width // Draw the upper line glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f(x, - ((gridspace * (n+1)*0.3)/2-(gridspace/2)), 0); glVertex3f(x, ((gridspace * (n+1)*0.3)/2-(gridspace/2)), 0); // Draw the lower line glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f(x, - ((gridspace * (n+1)*0.3)/2-(gridspace/2)), -5); glVertex3f(x, ((gridspace * (n+1)*0.3)/2-(gridspace/2)), -5); } } // Set up z lines (4 corners) - thickness to the plate glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f( - Gc, - Gc, 0); glVertex3f( - Gc, - Gc, -5); glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f( - Gc, (gridspace * n)/2-(gridspace/2), 0); glVertex3f( - Gc, (gridspace * n)/2-(gridspace/2), -5); glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f(- Gc + gridspace*(m-1), - Gc, 0); glVertex3f(- Gc + gridspace*(m-1), - Gc, -5); glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f(- Gc + gridspace*(m-1), (gridspace * n)/2-(gridspace/2), 0); glVertex3f(- Gc + gridspace*(m-1), (gridspace * n)/2-(gridspace/2), -5); glEnd(); //Draw circle (last wetted node) for (i=0; i<=n-1; i++) { for (j=1; j<=m; j++) { if (type[i*m+j]==1) { //'o' - display with a hollow white circle /*glBegin(GL_LINE_LOOP); //De-bug mode for flow fronts glColor3f(0.000f, 0.000f, 1.000f); for (k=0; k<=360; k+=5) { glVertex2f( (-(gridspace * n)/2-(gridspace/2)+j*gridspace) + sin(k) * 3.5, ( ((gridspace * n)/2-(gridspace/2) - (i*gridspace)) + cos(k) * 3.5) ); }*/ glPushMatrix(); glTranslatef( (-(gridspace * n)/2-(gridspace/2)+j*gridspace), ((gridspace * n)/2-(gridspace/2) - (i*gridspace)),0 ); glColor3f(0.000f, 0.000f, 1.000f); glCallList( circle ); glPopMatrix(); } else if (type[i*m+j]==0) { //'i' - display with a red cube glPushMatrix(); glTranslatef( (-(gridspace * n)/2-(gridspace/2)+j*gridspace), ((gridspace * n)/2-(gridspace/2) - (i*gridspace)),0 ); glColor3f(1.0f, 0.0f, 0.0f); glCallList( circle ); glPopMatrix(); } else if (type[i*m+j]==2) { //'x' - display with a white filled circle glBegin(GL_TRIANGLE_FAN); //COLOR CODE if (pres[i*m+j] >= 0 && pres[i*m+j] < inpres*1000/12*1) glColor3f(0.000f, 0.000f, 1.000f); //Slate Blue if (pres[i*m+j] >= inpres*1000/12*1 && pres[i*m+j] < inpres*1000/12*2) glColor3f(0.000f, 0.5000f, 1.000f); //Sky Blue if (pres[i*m+j] >= inpres*1000/12*2 && pres[i*m+j] < inpres*1000/12*3) glColor3f(0.000f, 0.800f, 1.000f); //Medium Torquoise if (pres[i*m+j] >= inpres*1000/12*3 && pres[i*m+j] < inpres*1000/12*4) glColor3f(0.000f, 1.000f, 1.000f); //Aquamarine if (pres[i*m+j] >= inpres*1000/12*4 && pres[i*m+j] < inpres*1000/12*5) glColor3f(0.000f, 1.000f, 0.600f); //Spring Green if (pres[i*m+j] >= inpres*1000/12*5 && pres[i*m+j] < inpres*1000/12*6) glColor3f(0.000f, 1.000f, 0.000f); //Lime Green if (pres[i*m+j] >= inpres*1000/12*6 && pres[i*m+j] < inpres*1000/12*7) glColor3f(0.500f, 0.900f, 0.0f); //Green if (pres[i*m+j] >= inpres*1000/12*7 && pres[i*m+j] < inpres*1000/12*8) glColor3f(0.800f, 0.900f, 0.000f); //Medium Spring Green if (pres[i*m+j] >= inpres*1000/12*8 && pres[i*m+j] < inpres*1000/12*9) glColor3f(1.000f, 1.000f, 0.000f); if (pres[i*m+j] >= inpres*1000/12*9 && pres[i*m+j] < inpres*1000/12*10) glColor3f(1.000f, 0.800f, 0.000f); //Coral if (pres[i*m+j] >= inpres*1000/12*10 && pres[i*m+j] < inpres*1000/12*11) glColor3f(1.000f, 0.500f, 0.000f); if (pres[i*m+j] >= inpres*1000/12*11 && pres[i*m+j] < inpres*1000/12*12) glColor3f(1.0f, 0.0f, 0.0f); //changed to Red for (k=0; k<=360; k+=15) { glVertex2f( (-(gridspace * n)/2-(gridspace/2)+j*gridspace) + sin(k*0.0174) * 3.5, ( ((gridspace * n)/2-(gridspace/2) - (i*gridspace)) + cos(k*0.0174) * 3.5) ); } glEnd(); } else if (type[i*m+j]==4) { //'+' - display with a white cube glColor3f(0.9882f, 0.9882f, 0.9882f); glRectf((-(gridspace * n)/2-(gridspace/2)+j*gridspace) - 4, ( ((gridspace * n)/2-(gridspace/2) - i*gridspace) ) -4, (-(gridspace * n)/2-(gridspace/2)+j*gridspace) + 4, ( ((gridspace * n)/2-(gridspace/2) - i*gridspace) ) +4); glEnd(); } }//end of for j }//end of for i for (i=0; i<=n-1; i++) { for (j=1; j<=m; j++) { //Flow front display if (xseg[i*m+j] <= 0.999 && xseg[i*m+j] >= -0.01) { //xseg has a value if (type[i*m+j]==3 && (type[i*m+j+1]==1 || type[i*m+j+1]==0 || type[i*m+j+1]==2)) { glPushMatrix(); glTranslatef( -(gridspace * n)/2-(gridspace/2)+(j+1)*gridspace - (gridspace*xseg[i*m+j]), ((gridspace * n)/2 - (gridspace/2) - i*gridspace),0); glColor3f(0.000f, 0.000f, 1.000f); glCallList( circle ); glPopMatrix(); } else if ((type[i*m+j]==1 || type[i*m+j]==0 || type[i*m+j]==2) && type[i*m+j+1]==3) { glPushMatrix(); glTranslatef( -(gridspace * n)/2-(gridspace/2)+j*gridspace + (gridspace*xseg[i*m+j]) , ((gridspace * n)/2 - (gridspace/2) - i*gridspace),0); glColor3f(0.000f, 0.000f, 1.000f); glCallList( circle ); glPopMatrix(); } } }//end of for j }//end of for i for (i=0; i<=n-2; i++) { for (j=1; j<=m; j++) { if (yseg[i*m+j] <= 0.999 && yseg[i*m+j] >= -0.01) { //yseg has a value if (type[i*m+j]==3 && (type[i*m+j+m]==1 || type[i*m+j+m]==0 || type[i*m+j+m]==2)) { glPushMatrix(); glTranslatef( (-(gridspace * n)/2-(gridspace/2)+j*gridspace) , ((gridspace * n)/2-(gridspace/2) - (i+1)*gridspace) + (gridspace*yseg[i*m+j]),0); glColor3f(0.000f, 0.000f, 1.000f); glCallList( circle ); glPopMatrix(); } else if ( (type[i*m+j]==1 || type[i*m+j]==0 || type[i*m+j]==2) && type[i*m+j+m]==3) { glPushMatrix(); glTranslatef( (-(gridspace * n)/2-(gridspace/2)+j*gridspace) , ((gridspace * n)/2-(gridspace/2) - i*gridspace) - (gridspace * yseg[i*m+j]),0); glColor3f(0.000f, 0.000f, 1.000f); glCallList( circle ); glPopMatrix(); } } } } if (NumFlag == true) { //Set up node number fonts int nodecount=0; for (y = (gridspace * n)/2-(gridspace/2); y >= - Gc; y -= gridspace) { for (x = - Gc ; x <= - Gc + gridspace*(m-1); x += gridspace) { nodecount += 1; glColor3f(1.0f, 1.0f, 1.0f); _snprintf(text_buffer, 40, "%d", nodecount ); render_text( x-2.5,y, text_buffer ); } } } if (LegendFlag == true) { int in, la, dv; glBegin(GL_LINES); glLineWidth(0.5); glColor3f(1.0f, 1.0f, 1.0f); for (la = 8; la <= 104; la += 8) { glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - la); glVertex2f(- Gc - 43, (gridspace * n)/2-(gridspace/2) - la); } glEnd(); in = inpres * 1000; for (dv = 12, la = 8; dv >= 0 && la <= 104; dv --, la += 8) { _snprintf(text_buffer, 40, "%d", in * dv/12); render_text( - Gc - 39, (gridspace * n)/2-(gridspace/2) - la, text_buffer ); } glBegin(GL_QUADS); glColor3f(1.000f, 0.000f, 0.000f); //Red glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 8); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 8); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 16); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 16); glColor3f(1.000f, 0.500f, 0.000f); //Orange Red glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 16); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 16); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 24); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 24); glColor3f(1.000f, 0.800f, 0.000f); //Coral glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 24); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 24); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 32); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 32); glColor3f(1.000f, 1.000f, 0.000f); //Yellow glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 32); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 32); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 40); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 40); glColor3f(0.800f, 0.900f, 0.000); //Medium Spring Green glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 40); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 40); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 48); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 48); glColor3f(0.5f, 0.9f, 0.0f); //Green glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 48); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 48); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 56); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 56); glColor3f(0.000f, 1.000f, 0.000f); //Lime Green glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 56); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 56); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 64); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 64); glColor3f(0.000f, 1.000f, 0.498f); //Spring Green glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 64); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 64); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 72); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 72); glColor3f(0.0f, 1.0f, 1.0f); //Aquamarine glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 72); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 72); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 80); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 80); glColor3f(0.0f, 0.8f, 1.0f); //Medium Torquoise glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 80); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 80); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 88); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 88); glColor3f(0.0f, 0.5f, 1.0f); //Sky Blue glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 88); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 88); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 96); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 96); glColor3f(0.0f, 0.0f, 1.0f); //Slate Blue glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 96); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 96); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 104); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 104); glEnd(); _snprintf(text_buffer, 40, "UNIT: Pa"); glColor3f(1.000f, 1.000f, 1.000f); render_text( - Gc - 50, (gridspace * n)/2-(gridspace/2) - 116, text_buffer ); } // Restore transformations glPopMatrix(); // Flush drawing commands glutSwapBuffers(); glutPostRedisplay(); //change buffer, 2 buffers enables smooth drawing in one go glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(eyeX,eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ); } void SetupRC(void) { // Black background glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); } void ChangeSize(int w, int h) { GLfloat fAspect; // Prevent a divide by zero if(h == 0) h = 1; // Set Viewport to window dimensions glViewport(0, 0, w, h); fAspect = (GLfloat)w/(GLfloat)h; // Reset coordinate system glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Produce the perspective projection gluPerspective(5.0f, fAspect, 1.0, 6000.0); } void OtherKeys(unsigned char key, int z, int a) { if(key == 't') { // 't' starts the flow during manual mode if (GeometryFlag==false) GeometryFlag=true; else if (GeometryFlag==true) GeometryFlag=false; } if (GeometryFlag==true) { front(); } if (SolutionFlag==true) { matcalc3(); SolutionFlag=false; } if(key == 'n') { // 'n' toggles the node number display on/off if (NumFlag==false) NumFlag=true; else if (NumFlag==true) NumFlag=false; } if(key == 'p') { // 'p' pauses the flow during auto mode cout << "Paused." << "\n"; system ("pause"); } if (key == 'l') { // 'l' toggles the legend displa on/off if (LegendFlag==false) LegendFlag=true; else if (LegendFlag==true) LegendFlag=false; } if (key == ']') { // ']' increases the time step during flow t += 1; } if (key == '[') { // ']' increases the time step during flow t -= 1; } if(key == 'q') { // 'q' zoodel_x in the view eyeZ += 25; } if(key == 'a') { // 'a' zoodel_x out the view eyeZ -= 25; } } void SpecialKeys(int key, int x, int y) { if(key == GLUT_KEY_UP) { //rotates about x xRot -= 5.0f; } if(key == GLUT_KEY_DOWN) { xRot += 5.0f; } if(key == GLUT_KEY_LEFT) { //rotates about y yRot -= 5.0f; } if(key == GLUT_KEY_RIGHT) { yRot += 5.0f; } if(key == GLUT_KEY_HOME) { //rotates about z zRot -= 5.0f; } if(key == GLUT_KEY_END) { zRot += 5.0f; } if(key == GLUT_KEY_PAGE_UP) { //pans along x-positive eyeX -= 5.0f; centerX -= 5.0f; } if(key == GLUT_KEY_INSERT) { //pans along x-negative eyeX += 5.0f; centerX += 5.0f; } if(zRot > 356.0f) zRot = 0.0f; if(zRot < -1.0f) zRot = 355.0f; if(xRot > 356.0f) xRot = 0.0f; if(xRot < -1.0f) xRot = 355.0f; if(yRot > 356.0f) yRot = 0.0f; if(yRot < -1.0f) yRot = 355.0f; } int main (int argc, char **argv) { //last = GetTickCount(); //Comment THIS out TO GO MANUAL/////////////////////////////////////////////////////////////////////////////////////////////////// int k; cout << "Enter distance between the nodes (m): "; cin >> del_x; cout << "\n"; cout << "Enter time step (s): "; cin >> t; cout << "\n"; cout << "Enter viscosity of resin: "; cin >> visco; cout << "\n"; cout << "Enter porosity of fibre: "; cin >> poro; cout << "\n"; matcalc2(); // This section gets run once, before you ever render // Tells GL we are creating a new list glNewList( circle, GL_COMPILE ); glBegin(GL_TRIANGLE_FAN); for (k=0; k<=360; k+=15) glVertex2f( sin(k*0.0174) * 3.5, cos(k*0.0174) * 3.5 ); glEnd(); glEndList(); glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(1152,864); glutCreateWindow("Simulation of VARTM Resin Impregnation Process"); glutReshapeFunc(ChangeSize); glutSpecialFunc(SpecialKeys); glutDisplayFunc(RenderScene); glutKeyboardFunc(OtherKeys); SetupRC(); glutMainLoop(); } This one does show me a few circles, but not every circle. I have to look in further to see what is going on but mean while I guess you could have a look as well. Cheers!
  12. pkiskool

    C++ openGL : Lag issue

    OK everyone. Thanks for the help... especially erissian. The text rendering works great and looks great. However, I don't think the drawing list is working properly, as I don't see anything on the screen anymore... No error or warning on the code... so I'm not sure what the problem is... Here's my source code. (lot shorter!0 //HEADER FILES #include "glut.h" #include <iostream> #include <iomanip> #include <fstream> #include <cstdlib> #include <cmath> #include <math.h> #include <string> #include <stdlib.h> #define TINY 1.0e-20; #define NRANSI #define GL_PI 3.1415f #include "nrutil.h" //NR #include "nrutil.cpp" //NR #include "ludcmp.h" //NR #include "lubksb.h" //NR #include "matcalc2.h" #include "matcalc3.h" #include "front.h" // Rotation amounts static GLdouble xRot = 0.0f; static GLdouble yRot = 0.0f; static GLdouble zRot = 0.0f; static GLdouble eyeX = 0.0f; static GLdouble eyeY = -1.0f; static GLdouble eyeZ = 2500.0f; static GLdouble centerX = 0.0f; static GLdouble centerY = 0.0f; static GLdouble centerZ = 0.0f; static GLdouble upX = 0.0f; static GLdouble upY = 0.0f; static GLdouble upZ = 1.0f; static GLdouble scale = 1.0f; bool GeometryFlag; bool ZoomInFlag; bool ZoomOutFlag; bool NumFlag; bool LegendFlag=true; int numb=0; GLdouble y, x; double gridspace = 12.0f; unsigned int now, last; //////////////////////////////////////////// // Text rendering function// ////////////////////////////////////////// void render_text(float x, float y, char* s) { glRasterPos2f(x,y); for ( unsigned int i=0; i < strlen( s ); i++ ) glutBitmapCharacter(GLUT_BITMAP_9_BY_15,s); } /////////////////////////////////////////////////////////// // Setup the rendering state ////////////////////////////////////////////////////////// // Called to draw scene void RenderScene(void) { /*now = GetTickCount(); //comment THIS (only // parts) out TO GO MANAUL//////////////////////////////////////////////////////////////////////////////// if (now-last>100){ //THE NUMBER HERE CONTROLS THE SPEED - 1000 IS 1 SECOND last = now; // front(); // if (SolutionFlag==true) {// matcalc3(); // SolutionFlag=false; // } // } //*/ int i, j; int Gc = gridspace*(n-1)/2, Gt = (gridspace * n)/2-(gridspace/2); double k; GLdouble fCurrSize; // Save current size // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT); // Save matrix state and do the rotation glPushMatrix(); glRotatef(xRot, 1.0f, 0.0f, 0.0f); glRotatef(yRot, 0.0f, 1.0f, 0.0f); glRotatef(zRot, 0.0f, 0.0f, 1.0f); char text_buffer[100]; // should be big enough _snprintf(text_buffer, 40, "FILL TIME %d SEC", filltime ); glColor3f(1.0f, 1.0f, 1.0f); render_text( 50-Gc, 5+Gc, text_buffer ); // Set up x lines for(y = - Gc; y <= (gridspace * n)/2-(gridspace/2); y += gridspace) { // Set the line width glLineWidth(2); // Draw the upper line glBegin(GL_LINES); glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f( - Gc, y, 0); glVertex3f(- Gc + gridspace*(m-1), y, 0); // Draw the lower line glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f( - Gc, y, - 5); glVertex3f(- Gc + gridspace*(m-1), y, - 5); } // Set up y lines for(x = - Gc; x <= - Gc + gridspace*(m-1); x += gridspace) { // Draw the upper line glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f(x, - Gc, 0); glVertex3f(x, Gc, 0); // Draw the lower line glBegin(GL_LINES); glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f(x, - Gc, -5); glVertex3f(x, Gc, -5); } //1D case if (n==1) { for(x = - Gc; x <= - Gc + gridspace*(m-1); x += gridspace) { // Set the line width // Draw the upper line glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f(x, - ((gridspace * (n+1)*0.3)/2-(gridspace/2)), 0); glVertex3f(x, ((gridspace * (n+1)*0.3)/2-(gridspace/2)), 0); // Draw the lower line glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f(x, - ((gridspace * (n+1)*0.3)/2-(gridspace/2)), -5); glVertex3f(x, ((gridspace * (n+1)*0.3)/2-(gridspace/2)), -5); } } // Set up z lines (4 corners) - thickness to the plate glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f( - Gc, - Gc, 0); glVertex3f( - Gc, - Gc, -5); glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f( - Gc, (gridspace * n)/2-(gridspace/2), 0); glVertex3f( - Gc, (gridspace * n)/2-(gridspace/2), -5); glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f(- Gc + gridspace*(m-1), - Gc, 0); glVertex3f(- Gc + gridspace*(m-1), - Gc, -5); glColor3f(0.1843f, 0.3098f, 0.1843f); glVertex3f(- Gc + gridspace*(m-1), (gridspace * n)/2-(gridspace/2), 0); glVertex3f(- Gc + gridspace*(m-1), (gridspace * n)/2-(gridspace/2), -5); glEnd(); //Draw circle (last wetted node) for (i=0; i<=n-1; i++) { for (j=1; j<=m; j++) { if (type[i*m+j]==1) { //'o' - display with a hollow white circle /*glBegin(GL_LINE_LOOP); //De-bug mode for flow fronts glColor3f(0.000f, 0.000f, 1.000f); for (k=0; k<=360; k+=5) { glVertex2f( (-(gridspace * n)/2-(gridspace/2)+j*gridspace) + sin(k) * 3.5, ( ((gridspace * n)/2-(gridspace/2) - (i*gridspace)) + cos(k) * 3.5) ); }*/ glBegin(GL_TRIANGLE_FAN); glColor3f(0.000f, 0.000f, 1.000f); for (k=0; k<=360; k+=15) { glVertex2f( (-(gridspace * n)/2-(gridspace/2)+j*gridspace) + sin(k*0.0174) * 3.5, ( ((gridspace * n)/2-(gridspace/2) - (i*gridspace)) + cos(k*0.0174) * 3.5) ); } glEnd(); } else if (type[i*m+j]==0) { //'i' - display with a red cube glBegin(GL_TRIANGLE_FAN); glColor3f(1.0f, 0.0f, 0.0f); //Red for (k=0; k<=360; k+=15) { glVertex2f( (-(gridspace * n)/2-(gridspace/2)+j*gridspace) + sin(k*0.0174) * 3.5, ( ((gridspace * n)/2-(gridspace/2) - (i*gridspace)) + cos(k*0.0174) * 3.5) ); } glEnd(); } else if (type[i*m+j]==2) { //'x' - display with a white filled circle glBegin(GL_TRIANGLE_FAN); //COLOR CODE if (pres[i*m+j] >= 0 && pres[i*m+j] < inpres*1000/12*1) glColor3f(0.000f, 0.000f, 1.000f); //Slate Blue if (pres[i*m+j] >= inpres*1000/12*1 && pres[i*m+j] < inpres*1000/12*2) glColor3f(0.000f, 0.5000f, 1.000f); //Sky Blue if (pres[i*m+j] >= inpres*1000/12*2 && pres[i*m+j] < inpres*1000/12*3) glColor3f(0.000f, 0.800f, 1.000f); //Medium Torquoise if (pres[i*m+j] >= inpres*1000/12*3 && pres[i*m+j] < inpres*1000/12*4) glColor3f(0.000f, 1.000f, 1.000f); //Aquamarine if (pres[i*m+j] >= inpres*1000/12*4 && pres[i*m+j] < inpres*1000/12*5) glColor3f(0.000f, 1.000f, 0.600f); //Spring Green if (pres[i*m+j] >= inpres*1000/12*5 && pres[i*m+j] < inpres*1000/12*6) glColor3f(0.000f, 1.000f, 0.000f); //Lime Green if (pres[i*m+j] >= inpres*1000/12*6 && pres[i*m+j] < inpres*1000/12*7) glColor3f(0.500f, 0.900f, 0.0f); //Green if (pres[i*m+j] >= inpres*1000/12*7 && pres[i*m+j] < inpres*1000/12*8) glColor3f(0.800f, 0.900f, 0.000f); //Medium Spring Green if (pres[i*m+j] >= inpres*1000/12*8 && pres[i*m+j] < inpres*1000/12*9) glColor3f(1.000f, 1.000f, 0.000f); if (pres[i*m+j] >= inpres*1000/12*9 && pres[i*m+j] < inpres*1000/12*10) glColor3f(1.000f, 0.800f, 0.000f); //Coral if (pres[i*m+j] >= inpres*1000/12*10 && pres[i*m+j] < inpres*1000/12*11) glColor3f(1.000f, 0.500f, 0.000f); if (pres[i*m+j] >= inpres*1000/12*11 && pres[i*m+j] < inpres*1000/12*12) glColor3f(1.0f, 0.0f, 0.0f); //changed to Red for (k=0; k<=360; k+=15) { glVertex2f( (-(gridspace * n)/2-(gridspace/2)+j*gridspace) + sin(k*0.0174) * 3.5, ( ((gridspace * n)/2-(gridspace/2) - (i*gridspace)) + cos(k*0.0174) * 3.5) ); } glEnd(); } else if (type[i*m+j]==4) { //'+' - display with a white cube glColor3f(0.9882f, 0.9882f, 0.9882f); glRectf((-(gridspace * n)/2-(gridspace/2)+j*gridspace) - 4, ( ((gridspace * n)/2-(gridspace/2) - i*gridspace) ) -4, (-(gridspace * n)/2-(gridspace/2)+j*gridspace) + 4, ( ((gridspace * n)/2-(gridspace/2) - i*gridspace) ) +4); glEnd(); } }//end of for j }//end of for i for (i=0; i<=n-1; i++) { for (j=1; j<=m; j++) { //Flow front display if (xseg[i*m+j] <= 0.999 && xseg[i*m+j] >= -0.01) { //xseg has a value if (type[i*m+j]==3 && (type[i*m+j+1]==1 || type[i*m+j+1]==0 || type[i*m+j+1]==2)) { //glBegin(GL_LINE_LOOP); glBegin(GL_TRIANGLE_FAN); glColor3f(0.000f, 0.000f, 1.000f); //Blue for (k=0; k<=360; k+=15) { glVertex2f( -(gridspace * n)/2-(gridspace/2)+(j+1)*gridspace - (gridspace*xseg[i*m+j]) + sin(k*0.0174) * 3.5, ((gridspace * n)/2 - (gridspace/2) - i*gridspace) + cos(k*0.0174) * 3.5); } glEnd(); } else if ((type[i*m+j]==1 || type[i*m+j]==0 || type[i*m+j]==2) && type[i*m+j+1]==3) { //glBegin(GL_LINE_LOOP); glBegin(GL_TRIANGLE_FAN); glColor3f(0.000f, 0.000f, 1.000f); //Blue for (k=0; k<=360; k+=15) { glVertex2f( -(gridspace * n)/2-(gridspace/2)+j*gridspace + (gridspace*xseg[i*m+j]) + sin(k*0.0174) * 3.5, ((gridspace * n)/2-(gridspace/2) - i*gridspace) + cos(k*0.0174) * 3.5); } glEnd(); } } }//end of for j }//end of for i for (i=0; i<=n-2; i++) { for (j=1; j<=m; j++) { if (yseg[i*m+j] <= 0.999 && yseg[i*m+j] >= -0.01) { //yseg has a value if (type[i*m+j]==3 && (type[i*m+j+m]==1 || type[i*m+j+m]==0 || type[i*m+j+m]==2)) { glBegin(GL_TRIANGLE_FAN); glColor3f(0.000f, 0.000f, 1.000f); //Blue for (k=0; k<=360; k+=15) { glVertex2f( (-(gridspace * n)/2-(gridspace/2)+j*gridspace) + sin(k*0.0174) * 3.5 , ((gridspace * n)/2-(gridspace/2) - (i+1)*gridspace) + (gridspace*yseg[i*m+j]) + cos(k*0.0174) * 3.5); } glEnd(); } else if ( (type[i*m+j]==1 || type[i*m+j]==0 || type[i*m+j]==2) && type[i*m+j+m]==3) { //glBegin(GL_LINE_LOOP); glBegin(GL_TRIANGLE_FAN); glColor3f(0.000f, 0.000f, 1.000f); //Blue for (k=0; k<=360; k+=15) { glVertex2f( (-(gridspace * n)/2-(gridspace/2)+j*gridspace) + sin(k*0.0174) * 3.5, ((gridspace * n)/2-(gridspace/2) - i*gridspace) - (gridspace * yseg[i*m+j]) + cos(k*0.0174) * 3.5); } glEnd(); } } } } if (NumFlag == true) { //Set up node number fonts int nodecount=0; for (y = (gridspace * n)/2-(gridspace/2); y >= - Gc; y -= gridspace) { for (x = - Gc ; x <= - Gc + gridspace*(m-1); x += gridspace) { nodecount += 1; glColor3f(1.0f, 1.0f, 1.0f); _snprintf(text_buffer, 40, "%d", nodecount ); render_text( x-2.5,y, text_buffer ); } } } if (LegendFlag == true) { int in, la, dv; glBegin(GL_LINES); glLineWidth(0.5); glColor3f(1.0f, 1.0f, 1.0f); for (la = 8; la <= 104; la += 8) { glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - la); glVertex2f(- Gc - 43, (gridspace * n)/2-(gridspace/2) - la); } glEnd(); in = inpres * 1000; for (dv = 12, la = 8; dv >= 0 && la <= 104; dv --, la += 8) { _snprintf(text_buffer, 40, "%d", in * dv/12); render_text( - Gc - 39, (gridspace * n)/2-(gridspace/2) - la, text_buffer ); } glBegin(GL_QUADS); glColor3f(1.000f, 0.000f, 0.000f); //Red glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 8); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 8); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 16); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 16); glColor3f(1.000f, 0.500f, 0.000f); //Orange Red glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 16); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 16); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 24); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 24); glColor3f(1.000f, 0.800f, 0.000f); //Coral glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 24); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 24); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 32); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 32); glColor3f(1.000f, 1.000f, 0.000f); //Yellow glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 32); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 32); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 40); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 40); glColor3f(0.800f, 0.900f, 0.000); //Medium Spring Green glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 40); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 40); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 48); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 48); glColor3f(0.5f, 0.9f, 0.0f); //Green glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 48); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 48); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 56); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 56); glColor3f(0.000f, 1.000f, 0.000f); //Lime Green glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 56); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 56); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 64); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 64); glColor3f(0.000f, 1.000f, 0.498f); //Spring Green glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 64); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 64); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 72); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 72); glColor3f(0.0f, 1.0f, 1.0f); //Aquamarine glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 72); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 72); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 80); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 80); glColor3f(0.0f, 0.8f, 1.0f); //Medium Torquoise glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 80); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 80); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 88); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 88); glColor3f(0.0f, 0.5000f, 1.000f); //Sky Blue glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 88); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 88); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 96); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 96); glColor3f(0.000f, 0.000f, 1.000f); //Slate Blue glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 96); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 96); glVertex2f(- Gc - 45, (gridspace * n)/2-(gridspace/2) - 104); glVertex2f(- Gc - 50, (gridspace * n)/2-(gridspace/2) - 104); glEnd(); } // Restore transformations glPopMatrix(); // Flush drawing commands glutSwapBuffers(); glutPostRedisplay(); //change buffer, 2 buffers enables smooth drawing in one go glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(eyeX,eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ); } void SetupRC(void) { // Black background glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); } void ChangeSize(int w, int h) { GLfloat fAspect; // Prevent a divide by zero if(h == 0) h = 1; // Set Viewport to window dimensions glViewport(0, 0, w, h); fAspect = (GLfloat)w/(GLfloat)h; // Reset coordinate system glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Produce the perspective projection gluPerspective(5.0f, fAspect, 1.0, 6000.0); } void OtherKeys(unsigned char key, int z, int a) { if(key == 't') { // 't' starts the flow during manual mode if (GeometryFlag==false) GeometryFlag=true; else if (GeometryFlag==true) GeometryFlag=false; } if (GeometryFlag==true) { front(); } if (SolutionFlag==true) { matcalc3(); SolutionFlag=false; } if(key == 'n') { // 'n' toggles the node number display on/off if (NumFlag==false) NumFlag=true; else if (NumFlag==true) NumFlag=false; } if(key == 'p') { // 'p' pauses the flow during auto mode cout << "Paused." << "\n"; system ("pause"); } if (key == 'l') { // 'l' toggles the legend displa on/off if (LegendFlag==false) LegendFlag=true; else if (LegendFlag==true) LegendFlag=false; } if (key == ']') { // ']' increases the time step during flow t += 1; } if (key == '[') { // ']' increases the time step during flow t -= 1; } if(key == 'q') { // 'q' zoodel_x in the view eyeZ += 25; } if(key == 'a') { // 'a' zoodel_x out the view eyeZ -= 25; } } void SpecialKeys(int key, int x, int y) { if(key == GLUT_KEY_UP) { //rotates about x xRot -= 5.0f; } if(key == GLUT_KEY_DOWN) { xRot += 5.0f; } if(key == GLUT_KEY_LEFT) { //rotates about y yRot -= 5.0f; } if(key == GLUT_KEY_RIGHT) { yRot += 5.0f; } if(key == GLUT_KEY_HOME) { //rotates about z zRot -= 5.0f; } if(key == GLUT_KEY_END) { zRot += 5.0f; } if(key == GLUT_KEY_PAGE_UP) { //pans along x-positive eyeX -= 5.0f; centerX -= 5.0f; } if(key == GLUT_KEY_INSERT) { //pans along x-negative eyeX += 5.0f; centerX += 5.0f; } if(zRot > 356.0f) zRot = 0.0f; if(zRot < -1.0f) zRot = 355.0f; if(xRot > 356.0f) xRot = 0.0f; if(xRot < -1.0f) xRot = 355.0f; if(yRot > 356.0f) yRot = 0.0f; if(yRot < -1.0f) yRot = 355.0f; } int main (int argc, char **argv) { //last = GetTickCount(); //Comment THIS out TO GO MANUAL/////////////////////////////////////////////////////////////////////////////////////////////////// cout << "Enter distance between the nodes (m): "; cin >> del_x; cout << "\n"; cout << "Enter time step (s): "; cin >> t; cout << "\n"; cout << "Enter viscosity of resin: "; cin >> visco; cout << "\n"; cout << "Enter porosity of fibre: "; cin >> poro; cout << "\n"; matcalc2(); //Draw after each time step glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(1152,864); glutCreateWindow("Simulation of VARTM Resin Impregnation Process"); glutReshapeFunc(ChangeSize); glutSpecialFunc(SpecialKeys); glutDisplayFunc(RenderScene); glutKeyboardFunc(OtherKeys); SetupRC(); glutMainLoop(); } [Edited by - pkiskool on March 10, 2009 1:46:57 PM]
  13. pkiskool

    C++ openGL : Lag issue

    OK, I feel pretty embarrassed everytime I write something here, because I know that my programming knowledge of pool is very shallow.... but nonetheless. That's life... so I live with it. So I realized that for glTranslatef, I just had to add z in the brackets. OK good. Now for snpirntf, I also realized that it requires stdio.h header file, and on top of that the command seem to be _snprintf and not just snprintf, so I made that change as well. Here is the error now: '_snprintf': cannot convert parameter 1 from 'char (*)[40]' to 'char *' Mike, I understand your frustration on me but... be nice...
  14. pkiskool

    C++ openGL : Lag issue

    Alright, only ONE error! Text rendering bit. snprintf: identifier not found Let me know what I should do. Thanks again! [Edited by - pkiskool on March 5, 2009 3:39:29 PM]
  15. pkiskool

    C++ openGL : Lag issue

    Ahhhh finally a helpful reply! Can't wait to try these out! Thanks and I'll let you know asap!
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!