Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » OpenLayer blitting logic :-\

This thread is locked; no one can reply to it. rss feed Print
OpenLayer blitting logic :-\
Matthew Dalrymple
Member #7,922
October 2006
avatar

I've been stuck on this problem for a while, no one seems to want or can help :-\. I'm back now to working on it. I've made progress from nothing showing to something showing :D. But not everything shows and the fact that I got something to show up was no more than trial and error.

This code is not in its natural form, I'm splicing it together to make one loop.

1 vector<uint> m_Map;
2 ...
3 
4 const uint ScreenRows = (SCREEN_H / m_Tiles->GetTileHeight());
5 const uint ScreenCols = (SCREEN_W / m_Tiles->GetTileWidth());
6 int Column = 0;
7 int Row = 0;
8
9 int Xpixel = 0;
10 int Ypixel = 0;
11
12 int CurScreenRow = 0;
13 int CurScreenCol = 0;
14
15 uint TileNumber = 0;
16 
17 // Cycle through and draw each tile at its location on the screen
18 while(Row < m_Height && Ypixel < m_Height * m_Tiles->GetTileHeight() && CurScreenRow < ScreenRows)
19 {
20 while(Column < m_Width && Xpixel < m_Width * m_Tiles->GetTileWidth() && CurScreenCol < ScreenCols)
21 {
22 TileNumber = m_Map.at((Row * m_Width + Column) * Layer);
23 m_Tiles->Draw(TileNumber, Xpixel, Ypixel, 1.0f);
24 Column++;
25 CurScreenCol++;
26 Xpixel += m_Tiles->GetTileWidth();
27 }
28 Xpixel = 0;
29 CurScreenCol = 0;
30 Column = Xpos;
31 Ypixel += m_Tiles->GetTileHeight();
32 Row++;
33 CurScreenRow++;
34 }

Aw screw it I don't feel like copying cTile->Draw into that loop here it is:

1bool cTile::Draw(uint TileNum, uint Xpos, uint Ypos, float Scale)
2{
3 if(!m_TileSet.IsValid())
4 {
5 cLogFile::Add("Tileset not valid");
6 return false;
7 }
8 float tileXpos = 0;
9 float tileYpos = 0;
10 
11 tileXpos = (float)((TileNum % m_Cols) * m_TileWidth);
12 tileYpos = (float)((TileNum / m_Cols) * m_TileHeight);
13 
14 m_TileSet.BlitStretched((float)Xpos - tileXpos, (float)Ypos - tileYpos, (float)m_TileWidth * 2.0, (float)m_TileHeight * 2.0, Clipped(tileXpos, tileYpos, m_TileWidth, m_TileHeight));
15 
16 return true;
17}

I am having to draw it double the size to get it to be the correct 1:1 scale size. And not all of the tiles draw correctly. I have sent output of the data to a log file and everything seems fine... I don't understand why some will draw now and others will not. Does BlitStretched stretch first then do the clipping based on the newly stretched image? Are my offsets in the drawing coords wrong? It seems weird that some tiles show up and others do not. What is most weird is that I have to multiply by 2 to get a normal sized tile. m-Height/Width are the correct value.

Here's what this looks like when drawing with just Blit()

{"name":"correctnz1.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/0\/e061904fec5b3c5098ac68c47e2d8c7f.png","w":646,"h":505,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/0\/e061904fec5b3c5098ac68c47e2d8c7f"}correctnz1.png

Here's what this looks like when drawing with the loop above BlitStretched()

{"name":"wrongee9.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/3\/1390a2b7e472f0d39cca36c4feb8ca1a.png","w":646,"h":505,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/3\/1390a2b7e472f0d39cca36c4feb8ca1a"}wrongee9.png

=-----===-----===-----=
I like signatures that only the signer would understand. Inside jokes are always the best, because they exclude everyone else.

Fladimir da Gorf
Member #1,565
October 2001
avatar

Somehow, I think the issue is with Clipped in this case. Could you attach the whole project so that I could take a look?

OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori)

Matthew Dalrymple
Member #7,922
October 2006
avatar

Alright, the full project is attached to the original post. 8-)

=-----===-----===-----=
I like signatures that only the signer would understand. Inside jokes are always the best, because they exclude everyone else.

Fladimir da Gorf
Member #1,565
October 2001
avatar

OK, I found the issue! Now stretching and clipping will work together. Though the stretching affects the original image, not the clipped part, so if you want double the normal size, you should pass double the size of the tiles-image.

OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori)

Matthew Dalrymple
Member #7,922
October 2006
avatar

Ok well how do I get this fixed version? I'm on the trunk directory of your SVN site. How do I grab everything at once and replace my old stuff?

EDIT: I'm guessing their is some kind of CVS like tool to get the new ones. I guess I can just manually look for the files that were updated a few hours ago.

=-----===-----===-----=
I like signatures that only the signer would understand. Inside jokes are always the best, because they exclude everyone else.

juvinious
Member #5,145
October 2004
avatar

You can grab a snapshot from my signature.

__________________________________________
Paintown

tobing
Member #5,213
November 2004
avatar

Matthew: You may use TortoiseSVN to get stuff from any SVN depot.

ImLeftFooted
Member #3,935
October 2003
avatar

Whats that status on OL working on windows?

tobing
Member #5,213
November 2004
avatar

I have setup everything for MSVC 7.1 with project files for OL and all dependencies. Works like a charm. Most sources are from SVN resp. CVS though.

Fladimir da Gorf
Member #1,565
October 2001
avatar

Quote:

Whats that status on OL working on windows?

Well, I have only Windows myself. I guess you mean MSVC ;)

OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori)

ImLeftFooted
Member #3,935
October 2003
avatar

I'm using mingw and I can't get OL to compile, boat loads of compiler errors.

Fladimir da Gorf
Member #1,565
October 2001
avatar

Juvinious fixed some build stuff yesterday, maybe it works now? At least it does for me, and I'm using MingW as well.

OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori)

Matthew Dalrymple
Member #7,922
October 2006
avatar

Dustin Dettmer: Well if you are using the Dev-C++ IDE then you just grab OpenLayer and it grabs everything it depends on. Go to file->new->Project Then under the MultiMedia tab there is a nice little OpenLayer project template :-D. Let the compiling begin :D

=-----===-----===-----=
I like signatures that only the signer would understand. Inside jokes are always the best, because they exclude everyone else.

ImLeftFooted
Member #3,935
October 2003
avatar

Sounds great but I'll need the source to do any real OL development :-/

tobing
Member #5,213
November 2004
avatar

Either get the nightly snapshot or get the source from SVN directly.

Matthew Dalrymple
Member #7,922
October 2006
avatar

Alright, well I got the scaling to work at a scale of 1 and I think I'm having a bit of a logistics problem when it comes to tiling these tiles at a scaled transformation. I'm probably using the Scale too much or not enough, I know I must be using it in the wrong way. I think I'm close though. So any help on the correct formula for scale tiling?

1// TileNum - The tiles representation in the array
2// Xpos && Ypos - The X and Y Coords in pixels.
3// Scale - the scale at which to draw the image
4bool cTile::Draw(uint TileNum, uint Xpos, uint Ypos, float Scale)
5{
6 // Just use the other method that draws normally
7 if(Scale == 1.0)
8 {
9 Draw(TileNum, Xpos, Ypos);
10 return true;
11 }
12 if(!m_TileSet.IsValid())
13 {
14 cLogFile::Add("Tileset not valid");
15 return false;
16 }
17 // these are the x and y coords of the tile inside the bitmap
18 float tileXpos = 0;
19 float tileYpos = 0;
20 
21 tileXpos = (float)((TileNum % m_Cols) * m_TileWidth);
22 tileYpos = (float)((TileNum / m_Cols) * m_TileHeight);
23
24 // this is x and y coords that the tile should be drawn at
25 float newX;
26 float newY;
27
28 newX = ((float)Xpos * Scale - tileXpos);
29 newY = ((float)Ypos * Scale - tileYpos);
30
31 // the width and height that should be used to draw the tile
32 float newWidth;
33 float newHeight;
34
35 newWidth = (float)m_TileSet.Width() * Scale;
36 newHeight = (float)m_TileSet.Height() * Scale;
37 
38 
39 m_TileSet.BlitStretched(newX, newY, newWidth, newHeight, Clipped(tileXpos, tileYpos, m_TileWidth * Scale, m_TileHeight * Scale));
40 
41 return true;
42}

=-----===-----===-----=
I like signatures that only the signer would understand. Inside jokes are always the best, because they exclude everyone else.

juvinious
Member #5,145
October 2004
avatar

ddustin said:

I'm using mingw and I can't get OL to compile, boat loads of compiler errors.

Could you post those errors and how you are compiling?

__________________________________________
Paintown

ImLeftFooted
Member #3,935
October 2003
avatar

mkdir OpenLayer
svn co http://svn.berlios.de/svnroot/repos/openlayer/trunk OpenLayer
cmd window:

1C:\Program Files\Apoint 2.0\OpenLayer> buildme.bat
2 
3Can't find freetype do you have it installed?
4Please specify where its located:
5example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
6ist in the directory)
7Enter ignore to disable ttf support or exit if you don't have it and quit setup.
8 
9 
10Can't find freetype do you have it installed?
11Please specify where its located:
12example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
13ist in the directory)
14Enter ignore to disable ttf support or exit if you don't have it and quit setup.
15 
16 
17Can't find freetype do you have it installed?
18Please specify where its located:
19example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
20ist in the directory)
21Enter ignore to disable ttf support or exit if you don't have it and quit setup.
22 
23 
24Can't find freetype do you have it installed?
25Please specify where its located:
26example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
27ist in the directory)
28Enter ignore to disable ttf support or exit if you don't have it and quit setup.
29 
30 
31Can't find freetype do you have it installed?
32Please specify where its located:
33example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
34ist in the directory)
35Enter ignore to disable ttf support or exit if you don't have it and quit setup.
36 
37 
38Can't find freetype do you have it installed?
39Please specify where its located:
40example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
41ist in the directory)
42Enter ignore to disable ttf support or exit if you don't have it and quit setup.
43 
44 
45Can't find freetype do you have it installed?
46Please specify where its located:
47example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
48ist in the directory)
49Enter ignore to disable ttf support or exit if you don't have it and quit setup.
50 
51 
52Can't find freetype do you have it installed?
53Please specify where its located:
54example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
55ist in the directory)
56Enter ignore to disable ttf support or exit if you don't have it and quit setup.
57 
58 
59Can't find freetype do you have it installed?
60Please specify where its located:
61example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
62ist in the directory)
63Enter ignore to disable ttf support or exit if you don't have it and quit setup.
64 
65 
66Can't find freetype do you have it installed?
67Please specify where its located:
68example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
69ist in the directory)
70Enter ignore to disable ttf support or exit if you don't have it and quit setup.
71 
72 
73Can't find freetype do you have it installed?
74Please specify where its located:
75example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
76ist in the directory)
77Enter ignore to disable ttf support or exit if you don't have it and quit setup.
78 
79 
80Can't find freetype do you have it installed?
81Please specify where its located:
82example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
83ist in the directory)
84Enter ignore to disable ttf support or exit if you don't have it and quit setup.
85 
86 
87Can't find freetype do you have it installed?
88Please specify where its located:
89example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
90ist in the directory)
91Enter ignore to disable ttf support or exit if you don't have it and quit setup.
92 
93 
94Can't find freetype do you have it installed?
95Please specify where its located:
96example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
97ist in the directory)
98Enter ignore to disable ttf support or exit if you don't have it and quit setup.
99 
100 
101Can't find freetype do you have it installed?
102Please specify where its located:
103example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
104ist in the directory)
105Enter ignore to disable ttf support or exit if you don't have it and quit setup.
106 
107 
108Can't find freetype do you have it installed?
109Please specify where its located:
110example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
111ist in the directory)
112Enter ignore to disable ttf support or exit if you don't have it and quit setup.
113 
114 
115Can't find freetype do you have it installed?
116Please specify where its located:
117example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
118ist in the directory)
119Enter ignore to disable ttf support or exit if you don't have it and quit setup.
120 
121 
122Can't find freetype do you have it installed?
123Please specify where its located:
124example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
125ist in the directory)
126Enter ignore to disable ttf support or exit if you don't have it and quit setup.
127 
128 
129Can't find freetype do you have it installed?
130Please specify where its located:
131example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
132ist in the directory)
133Enter ignore to disable ttf support or exit if you don't have it and quit setup.
134 
135 
136Can't find freetype do you have it installed?
137Please specify where its located:
138example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
139ist in the directory)
140Enter ignore to disable ttf support or exit if you don't have it and quit setup.
141 
142 
143Can't find freetype do you have it installed?
144Please specify where its located:
145example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
146ist in the directory)
147Enter ignore to disable ttf support or exit if you don't have it and quit setup.
148 
149 
150Can't find freetype do you have it installed?
151Please specify where its located:
152example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
153ist in the directory)
154Enter ignore to disable ttf support or exit if you don't have it and quit setup.
155 
156 
157Can't find freetype do you have it installed?
158Please specify where its located:
159example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
160ist in the directory)
161Enter ignore to disable ttf support or exit if you don't have it and quit setup.
162 
163 
164Can't find freetype do you have it installed?
165Please specify where its located:
166example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
167ist in the directory)
168Enter ignore to disable ttf support or exit if you don't have it and quit setup.
169 
170 
171Can't find freetype do you have it installed?
172Please specify where its located:
173example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
174ist in the directory)
175Enter ignore to disable ttf support or exit if you don't have it and quit setup.
176 
177 
178Can't find freetype do you have it installed?
179Please specify where its located:
180example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
181ist in the directory)
182Enter ignore to disable ttf support or exit if you don't have it and quit setup.
183 
184 
185Can't find freetype do you have it installed?
186Please specify where its located:
187example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
188ist in the directory)
189Enter ignore to disable ttf support or exit if you don't have it and quit setup.
190 
191 
192Can't find freetype do you have it installed?
193Please specify where its located:
194example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
195ist in the directory)
196Enter ignore to disable ttf support or exit if you don't have it and quit setup.
197 
198 
199Can't find freetype do you have it installed?
200Please specify where its located:
201example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
202ist in the directory)
203Enter ignore to disable ttf support or exit if you don't have it and quit setup.
204 
205 
206Can't find freetype do you have it installed?
207Please specify where its located:
208example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
209ist in the directory)
210Enter ignore to disable ttf support or exit if you don't have it and quit setup.
211 
212 
213Can't find freetype do you have it installed?
214Please specify where its located:
215example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
216ist in the directory)
217Enter ignore to disable ttf support or exit if you don't have it and quit setup.
218 
219 
220Can't find freetype do you have it installed?
221Please specify where its located:
222example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
223ist in the directory)
224Enter ignore to disable ttf support or exit if you don't have it and quit setup.
225 
226 
227Can't find freetype do you have it installed?
228Please specify where its located:
229example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
230ist in the directory)
231Enter ignore to disable ttf support or exit if you don't have it and quit setup.
232 
233 
234Can't find freetype do you have it installed?
235Please specify where its located:
236example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
237ist in the directory)
238Enter ignore to disable ttf support or exit if you don't have it and quit setup.
239 
240 
241Can't find freetype do you have it installed?
242Please specify where its located:
243example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
244ist in the directory)
245Enter ignore to disable ttf support or exit if you don't have it and quit setup.
246 
247 
248Can't find freetype do you have it installed?
249Please specify where its located:
250example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
251ist in the directory)
252Enter ignore to disable ttf support or exit if you don't have it and quit setup.
253 
254 
255Can't find freetype do you have it installed?
256Please specify where its located:
257example: c:/mingw (make sure lib/libfreetype.a and include/freetype2/freetype ex
258ist in the directory)
259Enter ignore to disable ttf support or exit if you don't have it and quit setup.
260 
261C:\dev-cpp
262Do you wish to drop TTF support? [y/N]
263 
264Do you wish to use FreeType directly and drop GlyphKeeper? [y/N]
265y
266Do you wish to drop PNG support? [y/N]
267 
268Do you wish to drop old API Support? [y/N]
269y
270Do you wish to drop State Changes? [y/N]
271 
272- Creating required directories -
273Creating directory obj/...
274Creating directory dep/...
275Creating directory lib/...
276- Starting compilation -
277Compiling src/Animation.cpp...
278src/Animation.cpp:1:25: Animation.hpp: No such file or directory
279src/Animation.cpp:3: error: expected namespace-name before ';' token
280src/Animation.cpp:3: error: `<type error>' is not a namespace
281src/Animation.cpp:8: error: `Animation' has not been declared
282src/Animation.cpp:8: error: `string' was not declared in this scope
283src/Animation.cpp:8: error: `string' was not declared in this scope
284src/Animation.cpp:8: error: expected primary-expression before "int"
285src/Animation.cpp:8: error: initializer expression list treated as compound expr
286ession
287src/Animation.cpp:8: error: expected `,' or `;' before '{' token
288src/Animation.cpp:20: error: `Animation' has not been declared
289src/Animation.cpp: In function `bool Update(float)':
290src/Animation.cpp:21: error: `currentFrame' undeclared (first use this function)
291
292src/Animation.cpp:21: error: (Each undeclared identifier is reported only once f
293or each function it appears in.)
294src/Animation.cpp:21: error: `framesPerTick' undeclared (first use this function
295)
296src/Animation.cpp:22: error: `frames' undeclared (first use this function)
297src/Animation.cpp: At global scope:
298src/Animation.cpp:31: error: expected init-declarator before '&' token
299src/Animation.cpp:31: error: expected `,' or `;' before '&' token
300
301C:\Program Files\Apoint 2.0\OpenLayer>

juvinious
Member #5,145
October 2004
avatar

DDustin:
Ok this is the obvious reason why I am deprecating cbuild and replacing the build system with cmake.
I assume you are using mingw and have make? If you don't mind trying again, could you grab this and install it?
Then in a cmd window in the directory in which you checked out the source do:

mkdir temp
cd temp
cmakesetup ../

From there you'll get a setup window, choose MinGW makefiles and then hit configure. You might want to fix anything that appears in red and set CMAKE_INSTALL_PREFIX to where you want openlayer to install to, ie c:/mingw. If everything is fine you should be able to just hit ok which then it'll have generated makefiles and drop you back to the cmd line. All you have to do then is 'make' and then 'make install'. :)

__________________________________________
Paintown

Matthew Dalrymple
Member #7,922
October 2006
avatar

My Question still hasn't been answered :-P I got 1 tile to scale horizontally (not vertically too :() by 3 times its original size, but then the rest don't scale. Or maybe my eyers are being deceptive. Any help with the above code would be nice. The code thats 4-5 posts up from this one.

=-----===-----===-----=
I like signatures that only the signer would understand. Inside jokes are always the best, because they exclude everyone else.

Go to: