Mercurial > fife-parpg
comparison engine/core/view/renderers/gridrenderer.cpp @ 579:b2feacaed53c
* Added the colorbuffer patch with a small change due to SDL. Performance boost between 20-30% under OpenGL.
* Improved the most renderers with setColor() function.
* Fixed the genericrenderer, is now tested whether the images are in the viewport.
* Fixed the gridrenderer, the grid is now drawn only up to the viewport.
* Changed the vertex functions in opengl/renderbackendopengl.cpp from vertex3f() to vertex2f().
* Improved the Editor, now you can use blocking, grid and coordinate renderer over gui or keys. Additionally, the colors can be changed with the settings.xml.
author | helios2000@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sat, 31 Jul 2010 17:46:19 +0000 |
parents | 16c2b3ee59ce |
children | e3140f01749d |
comparison
equal
deleted
inserted
replaced
578:54d83a0462ee | 579:b2feacaed53c |
---|---|
43 static Logger _log(LM_VIEWVIEW); | 43 static Logger _log(LM_VIEWVIEW); |
44 | 44 |
45 GridRenderer::GridRenderer(RenderBackend* renderbackend, int position): | 45 GridRenderer::GridRenderer(RenderBackend* renderbackend, int position): |
46 RendererBase(renderbackend, position) { | 46 RendererBase(renderbackend, position) { |
47 setEnabled(false); | 47 setEnabled(false); |
48 m_color.r = 0; | |
49 m_color.g = 255; | |
50 m_color.b = 0; | |
48 } | 51 } |
49 | 52 |
50 GridRenderer::GridRenderer(const GridRenderer& old): | 53 GridRenderer::GridRenderer(const GridRenderer& old): |
51 RendererBase(old) { | 54 RendererBase(old), |
55 m_color(old.m_color) { | |
52 setEnabled(false); | 56 setEnabled(false); |
53 } | 57 } |
54 | 58 |
55 RendererBase* GridRenderer::clone() { | 59 RendererBase* GridRenderer::clone() { |
56 return new GridRenderer(*this); | 60 return new GridRenderer(*this); |
57 } | 61 } |
58 | 62 |
59 GridRenderer::~GridRenderer() { | 63 GridRenderer::~GridRenderer() { |
64 } | |
65 | |
66 GridRenderer* GridRenderer::getInstance(IRendererContainer* cnt) { | |
67 return dynamic_cast<GridRenderer*>(cnt->getRenderer("GridRenderer")); | |
60 } | 68 } |
61 | 69 |
62 void GridRenderer::render(Camera* cam, Layer* layer, RenderList& instances) { | 70 void GridRenderer::render(Camera* cam, Layer* layer, RenderList& instances) { |
63 CellGrid* cg = layer->getCellGrid(); | 71 CellGrid* cg = layer->getCellGrid(); |
64 if (!cg) { | 72 if (!cg) { |
71 // //draw front quad | 79 // //draw front quad |
72 // // 1,1,1 | 80 // // 1,1,1 |
73 // //1,-1,1 | 81 // //1,-1,1 |
74 // //-1,-1,1 | 82 // //-1,-1,1 |
75 // //-1,1,1 | 83 // //-1,1,1 |
76 Point a,b,c,d; | 84 //We don't need the elevation box atm |
77 | 85 // Point a,b,c,d; |
78 | 86 // |
79 ScreenPoint copt1 =cam->toScreenCoordinates(ExactModelCoordinate(1,1,1) ); | 87 // |
80 ScreenPoint copt2 =cam->toScreenCoordinates(ExactModelCoordinate(1,-1,1) ); | 88 // ScreenPoint copt1 =cam->toScreenCoordinates(ExactModelCoordinate(1,1,1) ); |
81 Point coptt1(copt1.x,copt1.y); | 89 // ScreenPoint copt2 =cam->toScreenCoordinates(ExactModelCoordinate(1,-1,1) ); |
82 Point coptt2(copt2.x,copt2.y); | 90 // Point coptt1(copt1.x,copt1.y); |
83 m_renderbackend->drawLine(coptt1,coptt2 ,15, 15, 200); | 91 // Point coptt2(copt2.x,copt2.y); |
84 a = coptt1; | 92 // m_renderbackend->drawLine(coptt1,coptt2 ,15, 15, 200); |
85 | 93 // a = coptt1; |
86 copt1 =cam->toScreenCoordinates(ExactModelCoordinate(1,-1,1) ); | 94 // |
87 copt2 =cam->toScreenCoordinates(ExactModelCoordinate(-1,-1,1) ); | 95 // copt1 =cam->toScreenCoordinates(ExactModelCoordinate(1,-1,1) ); |
88 coptt1 = Point(copt1.x,copt1.y); | 96 // copt2 =cam->toScreenCoordinates(ExactModelCoordinate(-1,-1,1) ); |
89 coptt2 = Point(copt2.x,copt2.y); | 97 // coptt1 = Point(copt1.x,copt1.y); |
90 m_renderbackend->drawLine(coptt1,coptt2 ,15, 15, 200); | 98 // coptt2 = Point(copt2.x,copt2.y); |
91 b = coptt1; | 99 // m_renderbackend->drawLine(coptt1,coptt2 ,15, 15, 200); |
92 | 100 // b = coptt1; |
93 copt1 =cam->toScreenCoordinates(ExactModelCoordinate(-1,-1,1) ); | 101 // |
94 copt2 =cam->toScreenCoordinates(ExactModelCoordinate(-1,1,1) ); | 102 // copt1 =cam->toScreenCoordinates(ExactModelCoordinate(-1,-1,1) ); |
95 coptt1 = Point(copt1.x,copt1.y); | 103 // copt2 =cam->toScreenCoordinates(ExactModelCoordinate(-1,1,1) ); |
96 coptt2 = Point(copt2.x,copt2.y); | 104 // coptt1 = Point(copt1.x,copt1.y); |
97 m_renderbackend->drawLine(coptt1,coptt2 ,15, 15, 200); | 105 // coptt2 = Point(copt2.x,copt2.y); |
98 c = coptt1; | 106 // m_renderbackend->drawLine(coptt1,coptt2 ,15, 15, 200); |
99 | 107 // c = coptt1; |
100 copt1 =cam->toScreenCoordinates(ExactModelCoordinate(-1,1,1) ); | 108 // |
101 copt2 =cam->toScreenCoordinates(ExactModelCoordinate(1,1,1) ); | 109 // copt1 =cam->toScreenCoordinates(ExactModelCoordinate(-1,1,1) ); |
102 coptt1 = Point(copt1.x,copt1.y); | 110 // copt2 =cam->toScreenCoordinates(ExactModelCoordinate(1,1,1) ); |
103 coptt2 = Point(copt2.x,copt2.y); | 111 // coptt1 = Point(copt1.x,copt1.y); |
104 m_renderbackend->drawLine(coptt1,coptt2 ,15, 15, 20); | 112 // coptt2 = Point(copt2.x,copt2.y); |
105 d = coptt1; | 113 // m_renderbackend->drawLine(coptt1,coptt2 ,15, 15, 20); |
106 | 114 // d = coptt1; |
107 m_renderbackend->drawQuad(a,b,c,d,15, 15, 200); | 115 // |
116 // m_renderbackend->drawQuad(a,b,c,d,15, 15, 200); | |
108 // | 117 // |
109 // | 118 // |
110 // //draw back quad | 119 // //draw back quad |
111 copt1 =cam->toScreenCoordinates(ExactModelCoordinate(-1,-1,-1) ); | 120 // copt1 =cam->toScreenCoordinates(ExactModelCoordinate(-1,-1,-1) ); |
112 copt2 =cam->toScreenCoordinates(ExactModelCoordinate(-1,1,-1) ); | 121 // copt2 =cam->toScreenCoordinates(ExactModelCoordinate(-1,1,-1) ); |
113 coptt1 = Point(copt1.x,copt1.y); | 122 // coptt1 = Point(copt1.x,copt1.y); |
114 coptt2 = Point(copt2.x,copt2.y); | 123 // coptt2 = Point(copt2.x,copt2.y); |
115 m_renderbackend->drawLine(coptt1,coptt2 ,200, 200, 200); | 124 // m_renderbackend->drawLine(coptt1,coptt2 ,200, 200, 200); |
116 | 125 // |
117 copt1 =cam->toScreenCoordinates(ExactModelCoordinate(-1,1,-1) ); | 126 // copt1 =cam->toScreenCoordinates(ExactModelCoordinate(-1,1,-1) ); |
118 copt2 =cam->toScreenCoordinates(ExactModelCoordinate(1,1,-1) ); | 127 // copt2 =cam->toScreenCoordinates(ExactModelCoordinate(1,1,-1) ); |
119 coptt1 = Point(copt1.x,copt1.y); | 128 // coptt1 = Point(copt1.x,copt1.y); |
120 coptt2 = Point(copt2.x,copt2.y); | 129 // coptt2 = Point(copt2.x,copt2.y); |
121 m_renderbackend->drawLine(coptt1,coptt2 ,200, 200, 200); | 130 // m_renderbackend->drawLine(coptt1,coptt2 ,200, 200, 200); |
122 | 131 // |
123 copt1 =cam->toScreenCoordinates(ExactModelCoordinate(1,1,-1) ); | 132 // copt1 =cam->toScreenCoordinates(ExactModelCoordinate(1,1,-1) ); |
124 copt2 =cam->toScreenCoordinates(ExactModelCoordinate(1,-1,-1) ); | 133 // copt2 =cam->toScreenCoordinates(ExactModelCoordinate(1,-1,-1) ); |
125 coptt1 = Point(copt1.x,copt1.y); | 134 // coptt1 = Point(copt1.x,copt1.y); |
126 coptt2 = Point(copt2.x,copt2.y); | 135 // coptt2 = Point(copt2.x,copt2.y); |
127 m_renderbackend->drawLine(coptt1,coptt2 ,200, 200, 200); | 136 // m_renderbackend->drawLine(coptt1,coptt2 ,200, 200, 200); |
128 | 137 // |
129 copt1 =cam->toScreenCoordinates(ExactModelCoordinate(1,-1,-1) ); | 138 // copt1 =cam->toScreenCoordinates(ExactModelCoordinate(1,-1,-1) ); |
130 copt2 =cam->toScreenCoordinates(ExactModelCoordinate(-1,-1,-1) ); | 139 // copt2 =cam->toScreenCoordinates(ExactModelCoordinate(-1,-1,-1) ); |
131 coptt1 = Point(copt1.x,copt1.y); | 140 // coptt1 = Point(copt1.x,copt1.y); |
132 coptt2 = Point(copt2.x,copt2.y); | 141 // coptt2 = Point(copt2.x,copt2.y); |
133 m_renderbackend->drawLine(coptt1,coptt2 ,200, 200, 200); | 142 // m_renderbackend->drawLine(coptt1,coptt2 ,200, 200, 200); |
134 | 143 |
135 | 144 |
136 Rect cv = cam->getViewPort(); | 145 Rect cv = cam->getViewPort(); |
146 int cvx2 = cv.x+cv.w; | |
147 int cvy2 = cv.y+cv.h; | |
137 RenderList::const_iterator instance_it = instances.begin(); | 148 RenderList::const_iterator instance_it = instances.begin(); |
138 for (;instance_it != instances.end(); ++instance_it) { | 149 for (;instance_it != instances.end(); ++instance_it) { |
139 Instance* instance = (*instance_it)->instance; | 150 Instance* instance = (*instance_it)->instance; |
140 std::vector<ExactModelCoordinate> vertices; | 151 std::vector<ExactModelCoordinate> vertices; |
141 cg->getVertices(vertices, instance->getLocationRef().getLayerCoordinates()); | 152 cg->getVertices(vertices, instance->getLocationRef().getLayerCoordinates()); |
144 Point pt1(firstpt.x, firstpt.y); | 155 Point pt1(firstpt.x, firstpt.y); |
145 Point pt2; | 156 Point pt2; |
146 ++it; | 157 ++it; |
147 for (; it != vertices.end(); it++) { | 158 for (; it != vertices.end(); it++) { |
148 ScreenPoint pts = cam->toScreenCoordinates(cg->toMapCoordinates(*it)); | 159 ScreenPoint pts = cam->toScreenCoordinates(cg->toMapCoordinates(*it)); |
149 pt2.x = pts.x; pt2.y = pts.y; | 160 pt2.x = pts.x; |
161 pt2.y = pts.y; | |
150 Point cpt1 = pt1; | 162 Point cpt1 = pt1; |
151 Point cpt2 = pt2; | 163 Point cpt2 = pt2; |
152 /* FIXME: limit grid drawing to current camera view port | |
153 code below does not do it, but may act as a starting point | |
154 | |
155 int cvx2 = cv.x+cv.w; | |
156 int cvy2 = cv.y+cv.h; | |
157 | |
158 if (((pt1.x < cv.x) && (pt2.x < cv.x)) || | |
159 ((pt1.x > cvx2) && (pt2.x > cvx2)) || | |
160 ((pt1.y < cv.y) && (pt2.y < cv.y)) || | |
161 ((pt1.y > cvy2) && (pt2.y > cvy2))) { | |
162 pt1 = pt2; | |
163 continue; | |
164 } | |
165 | 164 |
166 if (cpt1.x < cv.x) cpt1.x = cv.x; | 165 if (cpt1.x < cv.x) cpt1.x = cv.x; |
167 if (cpt2.x < cv.x) cpt2.x = cv.x; | 166 if (cpt2.x < cv.x) cpt2.x = cv.x; |
168 if (cpt1.y < cv.y) cpt1.y = cv.y; | 167 if (cpt1.y < cv.y) cpt1.y = cv.y; |
169 if (cpt2.y < cv.y) cpt2.y = cv.y; | 168 if (cpt2.y < cv.y) cpt2.y = cv.y; |
170 if (cpt1.x > cvx2) cpt1.x = cvx2; | 169 if (cpt1.x > cvx2) cpt1.x = cvx2; |
171 if (cpt2.x > cvx2) cpt2.x = cvx2; | 170 if (cpt2.x > cvx2) cpt2.x = cvx2; |
172 if (cpt1.y > cvy2) cpt1.y = cvy2; | 171 if (cpt1.y > cvy2) cpt1.y = cvy2; |
173 if (cpt2.y > cvy2) cpt2.y = cvy2; | 172 if (cpt2.y > cvy2) cpt2.y = cvy2; |
174 */ | 173 |
175 m_renderbackend->drawLine(cpt1, cpt2, 0, 255, 0); | 174 m_renderbackend->drawLine(cpt1, cpt2, m_color.r, m_color.g, m_color.b); |
176 pt1 = pt2; | 175 pt1 = pt2; |
177 } | 176 } |
178 m_renderbackend->drawLine(pt2, Point(firstpt.x, firstpt.y), 0, 255, 0); | 177 if ((pt2.x >= cv.x) && (pt2.x <= cvx2) && (pt2.y >= cv.y) && (pt2.y <= cvy2)) { |
178 if ((firstpt.x >= cv.x) && (firstpt.x <= cvx2) && (firstpt.y >= cv.y) && (firstpt.y <= cvy2)) { | |
179 m_renderbackend->drawLine(pt2, Point(firstpt.x, firstpt.y), m_color.r, m_color.g, m_color.b); | |
180 } | |
181 } | |
179 } | 182 } |
180 } | 183 } |
184 | |
185 void GridRenderer::setColor(Uint8 r, Uint8 g, Uint8 b) { | |
186 m_color.r = r; | |
187 m_color.g = g; | |
188 m_color.b = b; | |
189 } | |
181 } | 190 } |