# Thread: The most difficut problem in OPENGL! (Try it)

1. ## The most difficut problem in OPENGL! (Try it)

To make a triangle move on the middle of a window horizontally (not back and forth) and the triangle should slowly disappear on one side and appear on other side slowly. (My prof claim no one can slove this problem, but who knows, maybe u guys are genius, try to solve this problem for me, thanks in advance!)

2. ## Re: The most difficut problem in OPENGL! (Try it)

Is this some kind of trick question, or did i misunderstand it?
Code :
```#include <GL/glut.h>

// --------------------------------------------------------------------------------
//
// --------------------------------------------------------------------------------
int viewportHeight;
int viewportWidth;

int trianglePos = 0;
int triangleSize = 120;

// --------------------------------------------------------------------------------
//
// --------------------------------------------------------------------------------
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);

glTranslatef(trianglePos, 0, 0);
glBegin(GL_TRIANGLES);
{
glVertex2i(0,                viewportHeight / 2);
glVertex2i(triangleSize / 2, viewportHeight / 2 + triangleSize);
glVertex2i(triangleSize,     viewportHeight / 2);
}
glEnd();

glTranslatef(-viewportWidth, 0, 0);
glBegin(GL_TRIANGLES);
{
glVertex2i(0,                viewportHeight / 2);
glVertex2i(triangleSize / 2, viewportHeight / 2 + triangleSize);
glVertex2i(triangleSize,     viewportHeight / 2);
}
glEnd();

glutSwapBuffers();
}

void reshape(int w, int h)
{
viewportWidth = w;
viewportHeight = h;

glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glOrtho(0, w, 0, h, -1, 1);
glMatrixMode(GL_MODELVIEW);
}

void idle(void)
{
++trianglePos;
if(trianglePos > viewportWidth) trianglePos = 0;

glutPostRedisplay();
}

int main(int argc, char **argv)
{
glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutCreateWindow("scrolling triangle");

glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(idle);

glutMainLoop();

return 0;
}```

3. ## Re: The most difficut problem in OPENGL! (Try it)

yea...that doesn't seem too hard. unless you want something like this:
Code :
```+----------------------+
|                      |
| /\                   |
|/  \                  |
|    \                /|
|     \              / |
|______\            /__|
|                      |
+----------------------+```
in this case, you'd need to check the position of each vertex of the triangle, and draw the lines separately.

b

4. ## Re: The most difficut problem in OPENGL! (Try it)

Or draw two triangles when the bounds approaches the edge.

Either the question isn't phrased correctly or your professor is a moron.

I doubt you'd find a professor quite this dumb so maybe you should try and solve your exercise questions before posting and making your prof. sound like an idiot.

5. ## Re: The most difficut problem in OPENGL! (Try it)

Or are you insinuating some sort of circular viewing plane?

6. ## Re: The most difficut problem in OPENGL! (Try it)

coredump, u got the point!exactly same as what i mean! the diffculty is how to do. what u siad si correct in theory, but how to put in code is big problem since i am still blur in OpenGL. Anyway, thanks for ur reply!

7. ## Re: The most difficut problem in OPENGL! (Try it)

the easiest way would be to do what dorbie suggested...when the triangle passes the right edge of the window, draw a second triangle coming in from the left side. when the triangle on the right is all the way past the window's edge, then just draw the second triangle. simple!

b

8. ## Re: The most difficut problem in OPENGL! (Try it)

That is more of an emulation of a simple triangle case. The algrithm for n cases is a bit different, but by no means impossible. The idea of wrapping is the way to go rather than trying t odo a 'real' circular viewing plane. Althought thinking about it a circular plane should nt be too difficult.

9. ## Re: The most difficut problem in OPENGL! (Try it)

An emulation? Give me a break. Now you're changing the rules. Talk about contriving to define a problem that doesn't exist. Any problem is tough if you tie someone's hands and exclude options after a trivial solution is presented. It's not an emulation. I could say most clipping hardware built is an emulation based on this kind of definition.

Go rasterize on a torroidal framebuffer with a guard band clip (that's the other simple solution) if you like. I'll stick with my first idea, it works on hardware. It's funny that this is posed as if it's a 'grand challenge' it's not, almost nobody wants to render like this, maybe someone writing an asteroids game, but that's about it.

Aha, you are writing an asteroids game aren't you. And you asked old prof a question he couldn't answer. This is almost funny now.

[This message has been edited by dorbie (edited 06-17-2002).]

10. ## Re: The most difficut problem in OPENGL! (Try it)

you are looking for 360 degree fov baby!
render into four side by side viewports with x fov 90 degrees and rotating the scene 90 degree in each viewport

Page 1 of 4 1234 Last

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•