Results 1 to 10 of 10

Thread: OpenGL Textures + Rotating

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default More Progress

    If I replace:

    glRotatef(xrot,1.0f,0.0f,0.0f);
    glRotatef(yrot,0.0f,1.0f,0.0f);
    glRotatef(zrot,0.0f,0.0f,1.0f);

    with:

    glRotatef(GLint(xrot),1.0f,0.0f,0.0f);
    glRotatef(GLint(yrot),0.0f,1.0f,0.0f);
    glRotatef(GLint(zrot),0.0f,0.0f,1.0f);

    It works. So why does glRotatef not work when passed a GLfloat but works when passed a GLint? Again, only on Windows. I have also tried glRotated, same results, only works when passed a GLint.

    *** Note: If you read my first post, this testing is done using approach one. Using approach two, these gl functions work as expected.

  2. #2
    Join Date
    May 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Qt Source

    Not sure if this will help anyone, but I was able to find the glRotatef function inside the Qt source code.


    #ifdef QT_OPENGL_ES_1_CL
    ...
    inline void glRotatef (GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
    {
    glRotatex(FLOAT2X(angle), FLOAT2X(x), FLOAT2X(y), FLOAT2X(z));
    }
    ...
    #endif //QT_OPENGL_ES_1_CL

    Not sure if this is being called. What does QT_OPENGL_ES_1_CL stand for?

  3. #3
    Join Date
    May 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default More From Source

    from qgl.cpp:

    ... (Line 2606)
    Note that under Windows, the QGLContext belonging to a QGLWidget
    has to be recreated when the QGLWidget is reparented. This is
    necessary due to limitations on the Windows platform. This will
    most likely cause problems for users that have subclassed and
    installed their own QGLContext on a QGLWidget. It is possible to
    work around this issue by putting the QGLWidget inside a dummy
    widget and then reparenting the dummy widget, instead of the
    QGLWidget. This will side-step the issue altogether, and is what
    we recommend for users that need this kind of functionality.
    ...

    Not sure if this helps anybody.

  4. #4
    Join Date
    May 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Found Solution

    Ok, I have found a solution that I can live with. It must have something to do with the paragraph from the last post. If I create a QGLContext before I create the QGLWidget, everything works. I don't even have to pass the QGLContext to the QGLWidget class for it to work, as long as the context is created before the widget.

    Here is my main:

    #include <QtGui/QApplication>
    #include <QGLContext>
    #include <QGLFormat>
    #include "glwidget.h"

    int main(int argc, char *argv[])
    {
    Q_INIT_RESOURCE(data);

    QApplication a(argc, argv);

    QGLFormat glFormat;
    QGLContext glContext(glFormat);
    glContext.create();

    GLWidget glWidget;
    glWidget.show();

    return a.exec();
    }

    This WORKS!!!

    If I comment out:

    QGLFormat glFormat;
    QGLContext glContext(glFormat);
    glContext.create();

    I doesn't work!!!

    Finally!!! I have figured out the problem. There's nothing like figuring out a problem that's been bugging you all day. I am going to sleep, it is almost 3 AM and I have to get up for work tomorrow to solve more programming problems, yay.

  5. #5
    Join Date
    May 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Why!!!

    I tried the solution from my last post at work today, and nothing. I am still having the problem!!! I am running Windows XP at work and Windows Vista at home, that is the only difference I can think of. So, I will go home for lunch today and recompile the code at home to make sure it works, then I will bring that same exact code to work to see if it works. Does anyone have any suggestions?

  6. #6
    Join Date
    May 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Solution

    Ok, I was able to get it to work by putting a qDebug command between the QGLContext and GLWidget.

    QGLFormat glFormat;
    QGLContext glContext(glFormat);
    glContext.create();
    qDebug() << "Create GL Widget";
    GLWidget glWidget; // Create GL Widget

    Without the qDebug command, it doesn't work. What is going on with this buggy code? What is Qt doing internally that I cannot seem to figure out? Where are the Qt guru's?

  7. #7
    Join Date
    May 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Stupid me!!!

    *** IGNORE ALL MY PREVIOUS POSTS!!! ***

    I recently looked back at my Qt + OpenGL examples and I finally figured out the problem I was having when I first started this Thread. If you read any of my previous posts, you know that I was having trouble getting a cube with a texture to show up on the screen. This had nothing to do with how Windows handles the OpenGL context or with Windows at all. This had everything to do with BAD programming.

    I have been programming for 8 - 9 years now. I program at work everyday, so I feel pretty STUPID for the mistake I made. I wanted to leave this last post so that people could laugh at the mistake, or at me, but more importantly so that nobody else makes the same mistake.

    The problem was that I forgot to initialize the xrot, yrot, and zrot variables which I use in

    glRotatef(xrot, 1.0f, 0.0f, 0.0f);
    glRotatef(yrot, 0.0f, 1.0f, 0.0f);
    glRotatef(zrot, 0.0f, 0.0f, 1.0f);

    I declared them in the header file but didn't initialize them in the constructor. A NOOB mistake, and I feel STUPID for making it. I guess all the extra code I added to fix the problem only moved the variables in the binary which resulted in them having different random values that worked.

    *** IMPORTANT ***
    DON'T FORGET TO INITIALIZE YOUR VARIABLES

Similar Threads

  1. OpenGL and Qt Question
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 18th April 2009, 18:04
  2. Qtopia Core & OpenGL ES?
    By zelko in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 28th May 2007, 07:21
  3. OpenGl textures in Qt
    By Ashitaka in forum Qt Programming
    Replies: 1
    Last Post: 28th November 2006, 15:45
  4. Switching textures in opengl??
    By Randulf in forum Qt Programming
    Replies: 2
    Last Post: 18th September 2006, 17:59
  5. Opengl - Textures - Qt
    By Alex63 in forum Installation and Deployment
    Replies: 1
    Last Post: 29th June 2006, 09:32

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.