#ifndef TEXTUREWIDGET_H
#define TEXTUREWIDGET_H

#define GL_GLEXT_PROTOTYPES 1

#include <stdio.h>
#include <Common.h>
#include <QGLShaderProgram>

#include <cmath>
#include <iostream>
#include <stdlib.h>

#include <QtOpenGL>
#include <QGLWidget>
#include <QtGui>

#include <list>
#include <vector>
#include <string>

#include <camera.h>
#include <objecte.h>
#include <cub.h>
#include <llum.h>
#include <volumen.h>

typedef Common::vec4  color4;
typedef Common::vec4  point4;

using namespace std;

class textureWidget : public QGLWidget
{
    Q_OBJECT

public:

    textureWidget();
    ~textureWidget();

    int xRotation();
    int yRotation();
    int zRotation();

    void refresh();
    void guardar();
    void initializeGL();

    void CameraToGL();
    void showRaycastingCPUResult(GLubyte *texture);

    void dades2DtoGPU(GLuint texName, GLint texWidth, GLint texHeight, GLubyte *texPtr);
    void cambibackground();

    static const int NumVertices = 4;
    point4 points[NumVertices];
    color4 colors[NumVertices];
    vec2 tex_coords[NumVertices];
    int Index;
    void resizeGL(int width, int height);

public slots:


signals:

    void RotationChanged(int dx, int dy);
    void PanChanged(int dx, int dy);
    void ZoomChanged(int positiu);
    void xRotationChanged(int angle);
    void yRotationChanged(int angle);

protected:

    void paintGL();

    int pointAtPosition(const QPoint &pos);

private slots:

private:

    void normalizeAngle(int *angle);
    void recrearObjeto();
    GLubyte* readPPM(FILE *fin, GLsizei *wid, GLsizei *ht);

    void InitShader( const char* vertexShaderFile,
                       const char* fragmentShaderFile );

    void initShadersGPU();
    void drawTexture();
    void creaPla();

    int gear1Rot;
    QPoint lastPos;
    bool background;

    Camera camera;
    Capsa3D capsaMinima;

    mat4 modelView;
    mat4 projection;

    int flag;

    QWidget *w;
    QLineEdit *nombreEditado;

    QGLShaderProgram *program;
};

#endif // TEXTUREWIDGET_H
