-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglwidget.cpp
More file actions
106 lines (89 loc) · 2.07 KB
/
glwidget.cpp
File metadata and controls
106 lines (89 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "glwidget.h"
#include <QtGui>
#include "QDebug"
//#include <GL/freeglut.h>
GLWidget::GLWidget(QWidget *parent) :
QGLWidget(parent)
{
m_image = NULL;
m_image2 = NULL;
m_u = 500;
m_v = 500;
msDown.setX( -1 );
}
void GLWidget::initializeGL()
{
glClearColor(0.5,0.5,0.5,1);
}
//opengl (0,0) is the left botton corner by the glViewPort definition
void GLWidget::paintGL()
{
if( m_image != NULL ){
glViewport(0, 0, m_u, m_v);
glClear( GL_COLOR_BUFFER_BIT );
glColor3f(1,0,0);
glRasterPos2f( -1,-1);
glDrawPixels( m_u, m_v, GL_RGBA, GL_UNSIGNED_BYTE, m_image );
}
if( msDown.x() != -1 ){
float xDown = (msDown.x()/(float)m_u)*2-1.0;
float yDown = (msDown.y()/(float)m_v)*2-1.0;
float xNow = (msNow.x()/(float)m_u)*2-1.0;
float yNow = (msNow.y()/(float)m_v)*2-1.0;
glBegin(GL_LINE_LOOP);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(xDown, yDown);
glVertex2f(xNow, yDown);
glVertex2f(xNow, yNow);
glVertex2f(xDown, yNow);
glEnd();
}
if( m_image2 != NULL ){
glViewport(0, 200, m_u, m_v);
glColor3f(1,0,0);
glRasterPos2f( -1,-1);
glDrawPixels( m_u, m_v, GL_RGBA, GL_UNSIGNED_BYTE, m_image2 );
}
}
void GLWidget::resizeGL( int w, int h )
{
}
void GLWidget::setImagePointer( unsigned char* image )
{
m_image = image;
}
void GLWidget::setImagePointer2( unsigned char* image2 )
{
m_image2 = image2;
}
void GLWidget::mousePressEvent(QMouseEvent *event)
{
msDown = event->pos();
msDown.setY( GLWIDGET_HEIGHT - msDown.y() );
}
void GLWidget::mouseMoveEvent(QMouseEvent *event)
{
msNow = event->pos();
msNow.setY( GLWIDGET_HEIGHT - msNow.y() );
repaint();
}
void GLWidget::mouseReleaseEvent(QMouseEvent *event)
{
msNow = event->pos();
msNow.setY( GLWIDGET_HEIGHT - msNow.y() );
if( msNow.x() == msDown.x() && msNow.y() == msDown.y() )
msDown.setX( -1 );
repaint();
}
void GLWidget::setImageSize( int w, int h )
{
m_u = w;
m_v = h;
}
void GLWidget::getMsSltInfo( int &msDownX, int &msDownY, int &msRlsX, int &msRlsY )
{
msDownX = msDown.x();
msDownY = msDown.y();
msRlsX = msNow.x();
msRlsY = msNow.y();
}