Calling 2 functions in an alternating manner in display function [closed] - c++

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I have a function that simply constructs a stick figure in 1 position
I have another function that builds a stick figure in another position.
I now want to call these functions alternatively so that the figure will appear to walk.
I'm not sure if I have to push and pop matrices.

For such rudimentary animation, will a boolean flag not do? (OpenGL doesn't even come into it here, it's merely logic)
I.e. in your draw method:
animate = !animate; // flip flag for 2 possible frames (boolean member variable)
if (animate) {
// draw position 1
} else {
// draw position 2
}
However, bear in mind this is just some quick sample code to get the idea across - it would result in every frame having the animation occur, which would likely occur so fast to be nauseating. You will have to apply time logic to it as well to make the simple animation not just appear as a blur.

Related

How to move objects in OpenGL independently [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Given I have several cubes drawn on the canvas, how can they be moved independently of each other? How to define distinct onmouseup/onmousedown/onmousemove listeners to each cube?
How to define distinct onmouseup/onmousedown/onmousemove listeners to each cube?
You normally have only one pointer on the screen, except in multitouch environments, or where individual pointers can be requested for each input device.
So having only one set of mouse event handlers is kind of natual. If you want some distinction between the objects, you must get creative and come up with some way to associate event position with the to be changed object. For example clicking on it.
OpenGL is just a drawing API. It doesn't deal with objects, it doesn't know what a mouse is, or what input events are and it doesn't manage a scene, which also means it won't give you free candy in form of per-object-listeners. All of this must be implemented by you (or some 3rd party library).

Low frame rate in OpenGL [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have a blender obj. file in an OpenGL application. I have also added a camera so that it will move in around that object (it's a building, so it's pretty large). The frame rate on it is awful.
Why is it slow and/or how can I make it faster?
void camera (void) {
glRotatef(xrot,1.0,0.0,0.0);
glRotatef(yrot,0.0,1.0,0.0);
glTranslated(-xpos,-ypos,-zpos); }
This is just my simple camera class. Just in case it helps.
There are some reasons your code might be slow:
You aren't using VertexBuffer objects
You are using the fixed function pipeline and not shaders
You aren't optimizing your drawing code that only areas are rendered which are visible ( look a.e. for bsp-trees )
After all you've a lot of optimizations to do. I would start with optimizing my render pipeline and remove the fixed function pipeline and start to use shaders and vertex-buffers.

C : printf changes course of program [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I've got a program that simulates collisions (circles) using openGL, GLUT, GLUI. Everything worked fine but when I changed my code a bit it began to do weird things.
I have 2 buttons, "play" and "step", "play" simulates the collisions updated with a timer, "step" also simulates but you've got to click it in order to go further.
Originally it did that but now the "play" button acts the same as "step". If I add a printf in my timer callback it all works perfectly...
What can I do ?
In my timer_cb I only have got :
// printf("something\n");
glutPostRedisplay();
glutTimerFunc(getDeltaT(), timer_cb, 0);
The I/O routines, like printf, introduce a sensible delay by calling them. To answer with a certain degree of correctness you show us the User Interface code, but I think I can guess...
Are you using threads? Maybe it can be a concurrency bug because the execution of the button event handler is not synchronized with the update logic?

A countdown timer in OpenGL [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I wish to creat a countdown timer in OpenGL. So I am just looking for a function that will be called every second based on the system clock which will decrease a set variable. I tried fiddling with glutTimerfunc but itcalls back only once. I need a similar setup but one that calls back multiple times.
Timers and timer functions are neither defined by C++ nor by OpenGL but rather by the operating system you are using.
However, since GLUT seems to define one, and you are using it, here we go:
In your timer function passed to glutTimerFunc, just call glutTimerFunc with the same parameters again. That way you will end up creating an infinite loop of timer callbacks.
Use some global variable or the int value passed to the timer function to determine when to break the loop.

How can i render a tiled map with C++/SDL [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I want to render tiles to the screen from a text file. I have the random terrain generator working, and I can move the data from the text file to a 2d vector. What I'm having trouble with is understanding how to give those tiles the coordinates they need to be rendered at. How would I go about assigning each tile its own coordinates relative to the camera?
I suggest checking this lua tutorial on how create a tile engine in great detail. You'll learn much more then what someone will be willing to post here on stack. Tile Engines as you will see from this tutorial, requires more then just a few lines of code. After you learn it here, it shouldn't be to hard for you to translate it to sdl/c++. Just a thought.
Its a good starting place.