cross platform - OpenGL object not rotating -
cross platform - OpenGL object not rotating -
so, i've been trying rotate single object in opengl/glut environment. after going through several questions on , like, i've written appears right code, no dice. know how create work?
ps: i've tried changing glmatrixmode projection, shows black screen. same thing happens if utilize glloadidentity(). here's rendering code
void display() { preprocessevents(); glclear(gl_color_buffer_bit|gl_depth_buffer_bit); glloadidentity(); glulookat(camera::position.x, camera::position.y, camera::position.z, camera::position.x+math::sind(camera::rotationangles.x)*math::cosd(camera::rotationangles.y), camera::position.y+math::cosd(camera::rotationangles.x), camera::position.z+math::sind(camera::rotationangles.x)*math::sind(camera::rotationangles.y), 0.0, 1.0, 0.0); glbegin(gl_triangles); glcolor3f(1, 0, 0); glvertex3f(-1, 0,-3); glcolor3f(0, 1, 0); glvertex3f(0.0f, 2.0f,-3); glcolor3f(0, 0, 1); glvertex3f(1.0f, 0.0f,-3); glend(); glbindtexture(gl_texture_2d, tex->textureid); glbegin(gl_quads); glcolor3f(1, 1, 1); gltexcoord2f(100, 100); glvertex3f(100,0,100); gltexcoord2f(-100, 100); glvertex3f(-100,0,100); gltexcoord2f(-100,-100); glvertex3f(-100,0,-100); gltexcoord2f(100,-100); glvertex3f(100,0,-100); glend(); glbindtexture(gl_texture_2d, 0); object1.draw(); gltranslatef(-10.0, 10.0, 0.0); glbindtexture(gl_texture_2d, tex2->textureid); gluquadrictexture(quad,1); glusphere(quad,10,20,20); glbindtexture(gl_texture_2d, 0); //relevant code starts here glmatrixmode(gl_modelview); glloadidentity(); glpushmatrix(); glrotatef(190, 0.0, 0.0, 1.0); glpopmatrix(); glutswapbuffers(); }
are aware glpushmatrix
, glpopmatrix
do? save , restore "current" matrix.
by enclosing rotation in , doing no actual drawing operation before restoring matrix entire sequence of code origin //relevant code starts here
pointless.
even if did not push/pop, rotation applied next time draw something. logically might think mean next time phone call display (...)
, 1 of first things in display (...)
replace current matrix identity matrix (line 3).
in honesty, should consider abandoning whatever resource using larn opengl. using deprecated functionality , missing few fundamentals. opengl 3.0 tutorial touch on basics of transformation matrices.
as why changing matrix mode projection produces black screen, because next time phone call display (...)
, glulookat
operates on projection matrix. in effect, wind applying photographic camera transformation twice. should add together glmatrixmode (gl_modelview)
origin of display (...)
avoid this.
opengl cross-platform glut glrotate
Comments
Post a Comment