🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Rotations in GL

Started by
13 comments, last by Ched45 23 years, 12 months ago
Hi all. I''m a newbie to OpenGl and have been trying to work out this problem for hours now. I''m using GLUT, as I don''t want to attempt Win 32 API. Following NeHe''s tutorial on rotation, I can''t seen to get it to work. I''m trying to rotate a triangle. //--------------------------------------------------------------------------- GLfloat rtri; //Declare variable for triangle void init ( void ) { glEnable ( GL_DEPTH_TEST ); glClearColor ( 0.0, 0.0, 0.0, 0.0 ); } void display (void) //needs to return a value of TRUE { glClear ( GL_COLOR_BUFFER_BIT / GL_DEPTH_BUFFER_BIT ); glLoadIdentity ( ); glPushMatrix ( ); glRotatef(rtri, 0.0f, 1.0f, 0.0f); //rotate triangle glTranslatef (-1.5f, 0.0f, -6.0f); //Translate triange glBegin(GL_TRIANGLES); //begin triangle glColor3f( 1.0f, 0.0f, 0.0f); glVertex3f(0.0f, 1.0f, 0.0f); glColor3f( 0.0f, 1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 0.0f); glColor3f( 0.0f, 0.0f, 1.0f); glVertex3f(1.0f, -1.0f, 0.0f); glEnd( ); //end triangle glPopMatrix ( ); glutSwapBuffers ( ); rtri +=0.2f; //increase rotation variable for triangle return TRUE; //Keep rotation going } void reshape(int w, int h) { glViewport ( 0, 0, w, h ); glMatrixMode ( GL_PROJECTION ); glLoadIdentity ( ); if ( h==0 ) gluPerspective ( 80, ( float ) w, 1.0, 5000.0 ); else gluPerspective ( 80, ( float ) w / ( float ) h, 1.0, 5000.0 ); glMatrixMode ( GL_MODELVIEW ); glLoadIdentity ( ); } // Main Loop int main ( int argc, char** argv ) { glutInit ( &argc, argv ); glutInitDisplayMode ( GLUT_RGB / GLUT_DOUBLE ); glutInitWindowSize ( 250, 250 ); glutCreateWindow ( argv[0] ); init ( ); glutReshapeFunc ( reshape ); glutKeyboardFunc ( keyboard ); glutDisplayFunc ( display ); //When display function is changed, errors show here. glutMainLoop ( ); return 0; } *************************************************************** I know that void display (void) needs to change as it doesn''t return a value. But when i try changing it to return a bool, int or float errors appear in "GLUTDISPLAYFUNC( display );" [C++Error] triangle.cpp(84): Cannot convert ''int (*)(float)'' to ''void (*)()''. [C++Error] triangle.cpp(84): Type mismatch in parameter ''func'' in call to ''__stdcall glutDisplayFunc(void (*)())''. Anyone help, what am I doing wrong? Is there another way? Thanx --Ched-- chris@ched45.com
--Ched--chris@ched45.com
Advertisement
GLUT doesn''t allow you to return things, the prototypes for the callback routines (such as your display() function) is:

void functionName( void );

So, your display() function can''t return a value.

Morgan
So, how would I rotate? Create another none GLUT function and call that for the rotation?

--Ched--
chris@ched45.com
--Ched--chris@ched45.com
hi Ched45

>>void display (void) //needs to return a value of TRUE
why?
Anyway,the function void display(void) must return...void! so you can''t return a bool or anything else.


>>glPopMatrix ( );
>>glutSwapBuffers ( );
>>rtri +=0.2f; //increase rotation variable for triangle
You ought to put glutSwapBuffers() at the last line of the display function : this way you know easily what your app do frame by frame.


hope that help
lunasol
oops! it seems to me that i take a too long time to write my answer last time
BTW you don''t need to create another function in order to rotate : each frame the display function is call (and all GLUT function : see glutMainLoop) so if you specify a rotation in your display function, each frame there will be a rotation in your scene. Hope that make sense!
lunasol
I''ll give that ago. Thanx. I''m a newbie, trying to do some basic OpenGL over the summer ( I''m 16 ). I knew some C/C++ and wanted to do something that looked good :o).

Thanx again


--Ched--
chris@ched45.com
--Ched--chris@ched45.com
I know you mentioned that you didn''t want to mess with the Win32 API, but I think you should reconsider using it as base code.. When I started programming in OpenGL ( sheesh some 6-8 months ago.. lol ) I considered GLUT.. and several times since..

But using the code from say lesson 1, you can essientially ignore the win32 API and concentrate on the OpenGL stuff like DrawGLScene() and InitGLScene() and what not..

I don''t like GLUT at all.. don''t know why.. other than I don''t feel like I''m programming OpenGL... that''s silly ain''t it...



anyway, my 2 cents,

bosco()
--leader of the free world .. or something ..
I''ll give it a go.....even if its just a copy and paste job....lol. NeHe''s tutorials look great and I understand most of the stuff, but trying to convert to GLUT is kinda hard. Thanx for the advice

Thanx

--Ched--
chris@ched45.com
--Ched--chris@ched45.com
Yep and that''s why I advise learning NeHe''s stuff first.. most of my first work was just the way I explained.. Ignoring the Win 32 api code and learning opengl calls..

It''s amazing, because now that I am fimilar with everything, converting between the two seems like it will be a breeze.. as a matter of fact I''m gonna be doing some of that this weekend..


good luck and feel free to post here if you need help.. seems like there''s some really cool people watching the threads..


bosco()
--leader of the free world .. or something ..
You mentioned you hate having to convert to GLUT, well, if you just want to compile the tutorials, then download the Mac source and recompile. It uses GLUT, so it''s perfectly portable, I''ve done it before.

Morgan

This topic is closed to new replies.

Advertisement