Qt_OpenGL: Moving Images in 3D space and moving images in qt_opengl

Source: Internet
Author: User

Qt_OpenGL: Moving Images in 3D space and moving images in qt_opengl

Qt_OpenGL: Moving Images in 3D space

//. H

#ifndef GLWIDGET_H#define GLWIDGET_H#include <QGLWidget>#include <QtOpenGL>class QGLWidget;class QTimer;typedef struct Stars{public:    int r, g, b;    GLfloat dist, angle;}Stars;class GLWidget : public QGLWidget{    Q_OBJECTpublic:    GLWidget(QWidget *parent = 0);    ~GLWidget();protected:    void initializeGL();    void paintGL();    void resizeGL(int w, int h);    void keyPressEvent(QKeyEvent*);    void timerEvent(QTimerEvent*);private:    bool fullscreen;    GLfloat rotate_angle;    GLfloat zoom;    GLfloat title;    GLfloat spin;    GLuint loop;    bool twinkle;    GLfloat blend;private:    void loadTextures();    GLuint texture[1];};#endif // GLWIDGET_H

//. Cpp

# Include "glwidget. h "# include <glut. h ># include <QtGui> # include <QtCore> // Well, I admit that all variables are not good. GLfloat light_ambient [4] = {0.5, 0.5, 0.5, 1.0 }; GLfloat light_diffiuse [4] = {1.0, 1.0, 1.0, 1.0}; GLfloat light_position [4] = {0.0, 0.0, 2.0, 0.0}; static const int num = 50; static Stars stars [num]; GLWidget: GLWidget (QWidget * parent): QGLWidget (parent) {fullscreen = false; rotate_angle = 0.0; zoom =-15.0; title = 90.0; spin = 0.1; loop = 0; twinkle = false; blend = false; startTimer (5);} void GLWidget: initializeGL () {setGeometry (300,150,500,500); loadTextures (); GL_SMOOTH; glClearColor (0.0, 0.0, 0.0); glClearDepth (0.5); glable (latency); glDepthFunc (GL_LEQUAL); glHint (latency, GL_NICEST); glBlendFunc (GL_SRC_ALPHA, GL_ONE); glable (GL_BLEND); // assign the initial value for num star objects (loop = 0; loop <num; ++ loop) {stars [loop]. angle = 0.0; stars [loop]. dist = (float (loop)/num) * 5.0; stars [loop]. r = rand () % 256; stars [loop]. g = rand () % 256; stars [loop]. B = rand () % 256 ;}} void GLWidget: paintGL () {glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBindTexture (GL_TEXTURE_2D, texture [0]); for (loop = 0; loop <num; ++ loop) {glLoadIdentity (); glTranslatef (0.0, 0.0, zoom); // move to glRotatef (title, 1.0, 0.0, 0.0); // rotate title glRotatef (stars [loop] along the X axis. angle, 0.0, 1.0, 0.0); // each star rotates along the Y axis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.