![]() |
| | #1 |
| Registered User Join Date: Nov 2009
Posts: 1
| OpenGL general question Code: for(int i=-0; i<10;i+=10)
{
glBegin(GL_QUADS);
glVertex2f(-5.0f,i);
glVertex2f(i,5.0f);
glVertex2f(5.0f,i);
glVertex2f(i,-5.0f);
glEnd();
}
for(int i=-500; i<500; i+=30)
{
glBegin(GL_LINES);
glVertex2f(600.0f,i); //much simpler than all of that .........
glVertex2f(-600.0f,i);
glVertex2f(i,600.0f);
glVertex2f(i,-600.0f);
glEnd();
}
drawFont("Test Blue");
Last edited by Bubba; 11-24-2009 at 12:13 AM. Reason: Edit: Here's my code. I also have keyboard commands rigged to switch statements under their keyboard function method. |
| scaraba is offline | |
| | #2 |
| Registered User Join Date: Oct 2008
Posts: 983
| Try: Code: glPushMatrix(); glTranslate(...); // Render your triangle here glPopMatrix(); |
| EVOEx is offline | |
| | #3 |
| dat is, vast staat Join Date: Jul 2008 Location: SE Queens
Posts: 6,612
| Fundamental to the possibility of motion is an "event loop" -- that is, a loop that continuously redraws the screen/window. OpenGL does not do that by itself. However, if you are using glut or SDL you probably are using an event loop if you have been following some kind of tutorial. If you are not sure, ask. With glut, you have your scene drawing function registered like this, then you initialize the main event loop: Code: glutDisplayFunc(drawScene); [...] glutMainLoop(); Code: glutPostRedisplay(); Then you just use the technique EVOEx mentioned. As is, your quad is centered on the origin. So, working with that example: Code: static float square[3] = {0.0f};
glTranslatef(square[0],square[1],square[2]);
glBegin(GL_QUADS);
for(int i=-0; i<10;i+=10) {
glVertex2f(-5.0f,i);
glVertex2f(i,5.0f);
glVertex2f(5.0f,i);
glVertex2f(i,-5.0f);
}
glEnd();
square[0]++;
square[1]++;
Note the scene drawing routine registered by glut does not accept parameters, so you must use either "static" variables or globals. Also noticed I put the for loop inside glEnd/Begin, which is a little more efficient.
__________________ C programming resources: GNU C Function and Macro Index -- glibc reference manual The C Book -- nice online learner guide Current ISO draft standard CCAN -- new CPAN like open source library repository GDB tutorial #1 -- gnu debugger tutorials -- GDB tutorial #2 cpwiki -- our wiki on sourceforge Last edited by MK27; 11-23-2009 at 09:13 AM. |
| MK27 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Question about openGL | two31d | C++ Programming | 0 | 01-29-2006 01:39 PM |
| quick OpenGL question | Thantos | Game Programming | 4 | 04-04-2004 08:46 AM |
| struct problem and general C question | techrolla | C Programming | 8 | 01-09-2004 01:37 AM |
| OpenGL question | Leeman_s | C++ Programming | 8 | 09-07-2002 11:17 AM |
| OpenGL question | kas2002 | Game Programming | 16 | 08-02-2002 12:29 PM |