Jump to content
  • Advertisement
Sign in to follow this  

Processing and displaying a cube

This topic is 4772 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello fellow OpenGL programmers! I have quite a dilemma...I am trying to enact the game of life onto a cube. It has no problem displaying the first state of the game of life, however when i tries to process the next state, it freezes up and doesn't display the next state. Yes, I have checked for infinite loops and tested the algorithm outside of opengl. Have I reached some limit for openGL to handle a 3-dimensional array of integers? What can cause this type of freeze? Here's part of the code: int DrawGLScene(GLvoid) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glLoadIdentity(); glTranslatef(x,y,z); int counta, countb, countc, state; GLfloat xheight = 0.0f, yheight = 0.0f; glRotatef(xrot,1.0f,0.0f,0.0f); glRotatef(yrot,0.0f,1.0f,0.0f); for(countb = 0; countb < 10; countb++) { yheight = 0.0f; for(countc = 0; countc < 10; countc++) { state = DisplayCube[0][countb][countc]; glBindTexture(GL_TEXTURE_2D, texture[state]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f((xheight-5.0f), (5.0f - yheight), 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f((xheight-4.0f), (5.0f - yheight), 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f((xheight-4.0f), (4.0f - yheight), 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f((xheight-5.0f), (4.0f - yheight), 0.0f); glEnd(); yheight = yheight + 1.0f; } xheight = xheight + 1.0f; } xrot+=xspeed; yrot+=yspeed; for(int delay = 0; delay < 1000000000; delay++); getnextState(); return TRUE; } void clearcubes() { int counta, countb, countc; for(counta = 0; counta < 6; counta++) for(countb = 0; countb < 10; countb++) for(countc = 0; countc < 10; countc++) DisplayCube[counta][countb][countc] = 0; for(counta = 0; counta < 6; counta++) for(countb = 0; countb < 12; countb++) for(countc = 0; countc < 12; countc++) statecube[counta][countb][countc] = 0; return; } void seedcube() { int counta, countb, countc; srand(time(NULL)); // clearcubes(); for(counta = 0; counta < 6; counta++) for(countb = 0; countb < 10; countb++) for(countc = 0; countc < 10; countc++) DisplayCube[counta][countb][countc] = rulesseed(); transfer(); return; } int rulesseed() { if(rand()%5 ==1 || rand()%5 == 2) { if(rand()%5==1) if(rand()%5==1) return 3; //seeds sick(3) neighbors else return 2; //seeds infected(2) neighbors return 1; //seeds live(1) neighbors } return 0; //seeds empty(0) neighbor } void transfer() { int counta, countb, countc; for(counta = 0; counta < 6; counta++) for(countb = 0; countb < 10; countb++) for(countc = 0; countc < 10; countc++) { statecube[counta][countb + 1][countc+1] = DisplayCube[counta][countb][countc]; } seedpadding(); } void seedpadding() { padfrontback(0); padfrontback(5); padtopbottom(1); padtopbottom(4); padleftright(2); padleftright(3); } void padfrontback(int side) { int count, num; if(side == 0) num = 11; else if(side == 5) num = 0; else return; for(count = 0; count < 11; count++) { statecube[1][count][num] = statecube[side][count][1]; statecube[2][count][num] = statecube[side][1][count]; statecube[3][count][num] = statecube[side][10][count]; statecube[4][count][num] = statecube[side][count][10]; } } void padtopbottom(int side) { int count, numa, numb; if(side == 1) { numa = 0; numb = 11; } else if(side == 4) { numa = 11; numb = 0; } else return; for(count = 0; count < 11; count++) { statecube[0][count][numa] = statecube[side][count][10]; statecube[2][numb][count] = statecube[side][1][count]; statecube[3][numb][count] = statecube[side][10][count]; statecube[5][count][numa] = statecube[side][count][1]; } } void padleftright(int side) { int count, num; if(side == 2) num = 0; else if(side == 3) num = 11; else return; for(count = 0; count < 11; count++) { statecube[0][num][count] = statecube[side][count][10]; statecube[1][num][count] = statecube[side][10][count]; statecube[4][num][count] = statecube[side][1][count]; statecube[5][num][count] = statecube[side][count][1]; } } void getnextState() { int counta, countb, countc; for(counta = 0; counta < 6; counta++) for(countb = 1; countb < 12; countb++) for(countc = 1; countc < 12; countc++) { DisplayCube[counta][countb - 1][countc - 1] = nextstate(counta,countb, countc); } transfer(); return; } int nextstate(int side, int column, int row) { int counta, countb, state, live = 0, sick = 0; for(counta = column -1; counta <= column+1; counta++) { for(countb = row -1; countb <= row + 1; countb++) { state = statecube[side][counta][countb]; if(state != 0 && state != 5 && state != 6) live++; if(state == 3 || state == 4) sick++; } } state = statecube[side][column][row]; switch(state) { case 0: if(live == 3) return 1; //have 3 neighbor, new life is born return 0; case 1: live--; //can't count yourself as neighbor if(live < 2 || live >=4) return 5; //dies from either loniless or crowding if(sick >= 2 || rand()%20 ==1) return 2; //live becomes infected from 2 sick neighbor or pop-up return 1; //no change case 2: return 3; //if cell infected, becomes sick despite neightbors case 3: live--; sick--; if(live >= 3 && sick == 0) return 1; //the village cures the sick return 4; //not cured and remains case 4: live--; sick--; if(live >= 3 && sick == 0) return 1; return 5; //if not cured, then the cell dies case 5: if(live >= 4) return 0; //grave is plowed for land due to crowding return 6; //remains a grave case 6: return 0; //becomes a land no matter what }; } [Edited by - jackalman on April 26, 2005 6:40:46 PM]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Not a cube but a 10X10 MATRIX?

Also where are your 1440 textures loaded? maybe I'm missing the point here?

Trager

Share this post


Link to post
Share on other sites
Well, right now im just testing ONE side of the cube to see if it works.
As for textures, they work just fine with the cube face.

The point is I want to know if my algorithm is causing the openGL window to freeze, because the source is apprantly coming from my getnextState() function and would like some advice from the experience openGL programmers on the forum.

Share this post


Link to post
Share on other sites
I haven't read through it, but I'm so often put off when people paste large chunks of code like that & give you unspecific problems.
It sounds to me like it's time you learnt how to debug.
You need to debug & find the exact point that the program fails or you need to locate the loop by means of placed breakpoints & frequent checking.
Output to a console or other developer window of important info like program location should also help you locate the cause of your problem. I can't be specific without knowing the ide you are using, but then I'm not upto date with most popular ides anyway.
Once you learn to help yourself it will be a great weight off your shoulders

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!