Jump to content
  • Advertisement
Sign in to follow this  
Tamior

Help check my code, pls

This topic is 4834 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

Hi, everybody :). I experience a problem with my code. And I don't know what causes this. The problem is my ship moves with occasional jerking and there are also some skipping frames or something. It looks very unpleasant. And I want to know what exactly is the cause of it. This is my protogame written in C++ with glut: the game. If somebody has time to check it and is willing to help, please do :). Thank you. P.S. I know the code is hilarious at best but it's my first try in game programming using OOP.

Share this post


Link to post
Share on other sites
Advertisement
It's hard to tell when given the entire source code. I just checked your main.cpp and there seems to be a problem in main(...).

glutDisplayFunc(myDisplay);
glutIdleFunc(myDisplay);

should be:

glutDisplayFunc(myDisplay);
glutIdleFunc(myIdle);


Tom

EDIT:
I also have a comment on your layout, if you care:
Please use more spacing. I find snippets like these completely unreadable:

void Asteroid::draw(void) {
glDisable(GL_TEXTURE_2D);
Asteroid *n=first;
while(n!=NULL) {
glColor3f(0.0, 1.0, 0.0);
glBegin(GL_POLYGON);
for(int i=0; i<64; i++) glVertex2i(n->center.x+n->radius*(cos((2*PI/64)*i)), n->center.y+n->radius*(sin((2*PI/64)*i)));
glEnd();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslatef(0.0, 480, 0.0);
glBegin(GL_POLYGON);
for(int i=0; i<64; i++) glVertex2i(n->center.x+n->radius*(cos((2*PI/64)*i)), n->center.y+n->radius*(sin((2*PI/64)*i)));
glEnd();
glPopMatrix();
glPushMatrix();
glTranslatef(0.0, -480.0, 0.0);
glBegin(GL_POLYGON);
for(int i=0; i<64; i++) glVertex2i(n->center.x+n->radius*(cos((2*PI/64)*i)), n->center.y+n->radius*(sin((2*PI/64)*i)));
glEnd();
glPopMatrix();
glPushMatrix();
glTranslatef(640.0, 0.0, 0.0);
glBegin(GL_POLYGON);
for(int i=0; i<64; i++) glVertex2i(n->center.x+n->radius*(cos((2*PI/64)*i)), n->center.y+n->radius*(sin((2*PI/64)*i)));
glEnd();
glPopMatrix();
glPushMatrix();
glTranslatef(-640.0, 0.0, 0.0);
glBegin(GL_POLYGON);
for(int i=0; i<64; i++) glVertex2i(n->center.x+n->radius*(cos((2*PI/64)*i)), n->center.y+n->radius*(sin((2*PI/64)*i)));
glEnd();
glPopMatrix();
n=n->next;
}
}



I suggest something like this:


void Asteroid::draw(void)
{
glDisable(GL_TEXTURE_2D);
Asteroid *n=first;

while(n!=NULL)
{
glColor3f(0.0, 1.0, 0.0);
glBegin(GL_POLYGON);
for(int i=0; i<64; i++)
{
glVertex2i(n->center.x + n->radius * (cos((2 * PI / 64) * i)),
n->center.y + n->radius * (sin((2 * PI / 64) * i)));
}
glEnd();

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslatef(0.0, 480, 0.0);
glBegin(GL_POLYGON);
for(int i=0; i<64; i++)
{
glVertex2i(n->center.x + n->radius * (cos((2 *PI / 64) * i)),
n->center.y + n->radius * (sin((2 * PI / 64) * i)));
glEnd();
glPopMatrix();

glPushMatrix();
glTranslatef(0.0, -480.0, 0.0);
glBegin(GL_POLYGON);
for(int i=0; i<64; i++)
glVertex2i(n->center.x + n->radius * (cos((2 * PI / 64) * i)),
n->center.y + n->radius * (sin((2 * PI / 64) * i)));
glEnd();
glPopMatrix();

glPushMatrix();
glTranslatef(640.0, 0.0, 0.0);
glBegin(GL_POLYGON);
for(int i=0; i<64; i++)
{
glVertex2i(n->center.x + n->radius * (cos((2 * PI / 64) * i)),
n->center.y + n->radius * (sin((2 * PI / 64) * i)));
glEnd();
glPopMatrix();

glPushMatrix();
glTranslatef(-640.0, 0.0, 0.0);
glBegin(GL_POLYGON);
for(int i=0; i<64; i++)
glVertex2i(n->center.x + n->radius * (cos((2 * PI / 64) * i)),
n->center.y + n->radius * (sin((2 * PI / 64) * i)));
glEnd();
glPopMatrix();

n = n->next;
}
}



This may be many more lines, but that's good: now I can read it. Anyway, it's up to you...
Also try to replace all constant numbers (like 64, -640, etc) by constant variables with a proper name. That will make it much more readable as well...

Tom

Share this post


Link to post
Share on other sites
Yes, I must acknowledge that the layout of some parts is not so good. But those parts are usually trivial.
And also separating the rendering and idle callbacks seems to not solve the problem...

Share this post


Link to post
Share on other sites
Really would like to hear opinion of those few people who have downloaded my stuff. At least on how does it run on your system. And do you notice those flaws that I have noticed? How would you describe them? As I really can't figure out what the hell is wrong. Almost lost my sleep because of it...

Share this post


Link to post
Share on other sites
I've always had the impression that glut is a little bulky itself. It's nice and all but I personally prefer to use my own win32 code which always seems to run smoothly.

I don't think glut was really written with game development in mind.

That said, you might want to look at using vsync or frame rate control to handle the problem...

Share this post


Link to post
Share on other sites
Quote:
Original post by Leo_E_49
I've always had the impression that glut is a little bulky itself. It's nice and all but I personally prefer to use my own win32 code which always seems to run smoothly.

I don't think glut was really written with game development in mind.

That said, you might want to look at using vsync or frame rate control to handle the problem...


Thanks for the answer. Vsync is on by default in the OpenGL properties of my graphic card. And it must be included in the project as well I assume (at least I'm sure I didn't turn it off). I'm going to implement frame rate control using the precision timer. Not sure if it will help though, but it is necessary nontheless for the rest of my application.
I know glut is inept in many ways, but I saw and I'm almost sure you saw too applications written with it that run smooth. I've read a lot of examples but still there are problems. It seems that I can't notice some small but important detail or something like that. And that's why I need another person's opinion.

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.

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!