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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "sludge/graphics.h"
#include "sludge/allfiles.h"
namespace Sludge {
extern int sceneWidth, sceneHeight;
#if 0
extern GLuint backdropTextureName;
#endif
void drawLine(int x1, int y1, int x2, int y2) {
int x, y;
bool backwards = false;
#if 0
if (x1 < 0)
x1 = 0;
if (y1 < 0)
y1 = 0;
if (x2 < 0)
x2 = 0;
if (y2 < 0)
y2 = 0;
if (x1 > sceneWidth)
x1 = sceneWidth - 1;
if (x2 > sceneWidth)
x2 = sceneWidth - 1;
if (y1 > sceneHeight)
y1 = sceneHeight - 1;
if (y2 > sceneHeight)
y2 = sceneHeight - 1;
if (x1 > x2) {
x = x2;
backwards = !backwards;
} else
x = x1;
if (y1 > y2) {
y = y2;
backwards = !backwards;
} else
y = y1;
int diffX = abs(x2 - x1);
int diffY = abs(y2 - y1);
if (!diffX) {
diffX = 1;
if (x == sceneWidth - 1)
x = sceneWidth - 2;
}
if (!diffY) {
diffY = 1;
if (y == sceneHeight - 1)
y = sceneHeight - 2;
}
setPixelCoords(true);
glLineWidth(2.0);
int xoffset = 0;
while (xoffset < diffX) {
int w = (diffX - xoffset < viewportWidth) ? diffX - xoffset : viewportWidth;
int yoffset = 0;
while (yoffset < diffY) {
int h = (diffY - yoffset < viewportHeight) ? diffY - yoffset : viewportHeight;
// Render the scene - first the old backdrop
glBindTexture(GL_TEXTURE_2D, backdropTextureName);
//glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
const GLfloat vertices[] = { (GLfloat)-x - xoffset, (GLfloat)1 - y - yoffset, 0., (GLfloat)sceneWidth - x - xoffset, (GLfloat)1 - y - yoffset, 0., (GLfloat)-x - xoffset,
(GLfloat)sceneHeight - y - yoffset, 0., (GLfloat)sceneWidth - x - xoffset, (GLfloat)sceneHeight - y - yoffset, 0. };
const GLfloat texCoords[] = { 0.0f, 0.0f, backdropTexW, 0.0f, 0.0f, backdropTexH, backdropTexW, backdropTexH };
glUseProgram(shader.texture);
setPMVMatrix(shader.texture);
drawQuad(shader.texture, vertices, 1, texCoords);
// Then the line
//FIXME:Removing the lines doesn't work, but also didn't work properly before.
GLint xo1 = -xoffset, xo2 = -xoffset;
if (!backwards) {
xo2 += diffX;
} else {
xo1 += diffX;
}
const GLint lineVertices[] = { xo1, -yoffset, 0, xo2, -yoffset + diffY, 0, };
glUseProgram(shader.color);
setPMVMatrix(shader.color);
glUniform4f(glGetUniformLocation(shader.color, "myColor"), 0.0f, 0.0f, 0.0f, 1.0f);
int vertexLoc = glGetAttribLocation(shader.color, "myVertex");
glEnableVertexAttribArray(vertexLoc);
glVertexAttribPointer(vertexLoc, 3, GL_INT, GL_FALSE, 0, lineVertices);
glDrawArrays(GL_LINES, 0, 2);
glDisableVertexAttribArray(vertexLoc);
glUseProgram(0);
// Copy Our ViewPort To The Texture
copyTexSubImage2D(GL_TEXTURE_2D, 0, x + xoffset, y + yoffset, viewportOffsetX, viewportOffsetY, w, h, backdropTextureName);
yoffset += viewportHeight;
}
xoffset += viewportWidth;
}
setPixelCoords(false);
#endif
}
} // End of namespace Sludge
|