Yet another rotate quad question

Started by
3 comments, last by grayaii 15 years ago
Hi, First, sorry for yet another post on rotating quad. I read so many posts here on rotation that I feel silly posting on this subject again. The problem is that I can successfully rotate my texture, but when I do, my mouse coordinate get rotated too. Here's a snippet from my render function:

        Gl.glBindTexture(Gl.GL_TEXTURE_2D, (uint)m_TextureId);

        Gl.glPushMatrix();

        Gl.glLoadIdentity();
        Gl.glRotatef(45.0f, 0.0f, 0.0f, 1.0f);

        Gl.glBegin(Gl.GL_QUADS);
        //... <snip>
        Gl.glEnd();

        Gl.glPopMatrix(); // <-- I thought this would do it, but I was wrong
        
        Gl.glLoadIdentity();
        Gl.glMatrixMode(Gl.GL_MODELVIEW);

The above code rotates my texture 45 degrees, but when I move the mouse up and down, it also moves at 45 degrees. I'm in simple 2D, this is a snippet of my Init function, when setting up my window:

        Glut.glutMotionFunc(new Glut.MotionCallback(MouseMove)); 

        Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
        Gl.glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
        Gl.glViewport(0, 0, 800, 600);
        Gl.glMatrixMode(Gl.GL_PROJECTION);
        Gl.glLoadIdentity();
        Gl.glOrtho(0, 800, 600, 0, -1, 1);
        Gl.glMatrixMode(Gl.GL_MODELVIEW);
        Gl.glDisable(Gl.GL_DEPTH_TEST);
        Gl.glLoadIdentity();

I feel I'm RTFM'ed all out, which is why I'm resorting to posting here. I suspect the solution is a one-liner in the render function, but for the life of me I can't figure it out.
Advertisement
The code you posted looks ok, so the error must lie elsewhere.

One line disturbs me: at the end of your rendering code you call Gl.glMatrixMode(Gl.GL_MODELVIEW); which implies you set another matrix mode before.

Are you sure about the matrix mode and that you're not transforming elsewhere?
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
Quote:One line disturbs me: at the end of your rendering code you call Gl.glMatrixMode(Gl.GL_MODELVIEW); which implies you set another matrix mode before.


He said he rotates the TEXTURE, not QUAD. Which yes is weird. Are you meaning to rotate the texture coordinates? --> (GL_TEXTURE_MATRIX)

OpenGL has nothing to do with input, so I don't know what your talking about. I think a small video would def help out on youtube.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Will do. I will create the minimal amount of code to display the problem (and hopefully, in the process of doing so, I will find the source of my bug.)

The "Gl.glMatrixMode(Gl.GL_MODELVIEW);" was my failed attempt at trying everything I could think of to get it to work. It should not be there and it's my mistake for leaving it there when I posted.

You're right when you say OpenGL has nothing to do with input. I should have mentioned that I use:

Glut.glutPassiveMotionFunc(new Glut.PassiveMotionCallback(MyMouseMoveFunc));

And draw my mouse icon based on the x/y coordinates passed into MyMouseMoveFunc.
oh geez, I figured it out. In my previous posting I mentioned "And draw my mouse icon based on the x/y coordinates passed into MyMouseMoveFunc.". Well, it turns out I'm also drawing my mouse pointer with those rotated coordinates. Argh. I don't know why I didn't see this from the beginning. Thanks for helping me out, dpadam450 and Lord_Evil.

This topic is closed to new replies.

Advertisement