# Opengl Timer Problem

Page 1 of 1

## 4 Replies - 5193 Views - Last Post: 23 February 2009 - 10:19 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=88382&amp;s=a9e5baca8cffb05764e7cf13ae064adb&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Zorn

Reputation: 0
• Posts: 3
• Joined: 22-February 09

# Opengl Timer Problem

Posted 22 February 2009 - 03:38 PM

Ok so I'm using Opengl and glut and all that good stuff, but I'm going to go insane trying to get this to work.

I have A Quad and I want to transform it to the left by 1.
But rather then just adding -1 to it's x position I want it move smoothly from where it is to where it's going.

So I figured I'd move it by -0.1 and wait some, 10 times like this.

```  void MoveQuad (int i ){

glutPostRedisplay();
}

for(int i = 0; i < 10; i++)

```

But instead of moving smoothly it just waits half a second and moves 1 to
the left.

if anybody could help that would be awsome.

This post has been edited by Zorn: 22 February 2009 - 05:55 PM

Is This A Good Question/Topic? 0

## Replies To: Opengl Timer Problem

### #2 Space_Bee

Reputation: 1
• Posts: 3
• Joined: 22-February 09

## Re: Opengl Timer Problem

Posted 23 February 2009 - 12:18 AM

taking a rough guess i'd just change the value to 0.05 or try a lower value?

taking a more thought out approach:

```
// I'm going to assume ur using this (X is a global variable)
glTranslatef(X, 0, 0.0);

// The speed to move at
Xpos = 0.05;

// simple condition to start it, you can just use what u did with a method call
if( X > -1)
{
X -= Xpos;
}
//or this
{
X -= Xpos;
}

```

This might work.

### #3 Tom9729

• Segmentation fault

Reputation: 181
• Posts: 2,642
• Joined: 30-December 07

## Re: Opengl Timer Problem

Posted 23 February 2009 - 07:06 AM

This isn't really how you want to do things with OpenGL because I'm guessing glutTimerFunc(..) blocks until its time is up.

My suggestion is to have a display/render function registered with glutDisplayFunc(..), and then an update/logic function for things like movement registered with glutIdleFunc(..).

This post has been edited by Tom9729: 23 February 2009 - 07:09 AM

### #4 Lillefix

Reputation: 37
• Posts: 204
• Joined: 19-September 08

## Re: Opengl Timer Problem

Posted 23 February 2009 - 11:21 AM

My guess would be that your position variables are ints rather than floats. This is hard to determine without the complete code though.

### #5 Zorn

Reputation: 0
• Posts: 3
• Joined: 22-February 09

## Re: Opengl Timer Problem

Posted 23 February 2009 - 10:19 PM

Quote

This isn't really how you want to do things with OpenGL because I'm guessing glutTimerFunc(..) blocks until its time is up.

What do you mean by block. You mean like stops the program till glutTimerFunc gets called.

Anyways I got it to work like this

```void Left (int i){

i++;
if(i == 11)
return;
glutPostRedisplay();
glutTimerFunc(50, Left, i);

}

```

I just call that and it moves smoothly to the left.