<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7752976851994353052</id><updated>2011-12-19T23:23:44.272-08:00</updated><category term='C++'/><category term='Topcoder'/><category term='disk io'/><category term='mmap'/><category term='directx'/><category term='Windows mobile'/><category term='directdraw'/><category term='fread'/><category term='best c codes'/><category term='do something'/><category term='handango'/><category term='performance'/><category term='write'/><category term='brain vita'/><category term='Visual C++'/><category term='brainvita'/><category term='Java'/><category term='vedic maths'/><category term='Algorithms'/><category term='openGL'/><category term='fwrite'/><category term='code reading'/><category term='touch'/><title type='text'>Agent Hunts....</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://agenthunts.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://agenthunts.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>AgentHunt</name><uri>http://www.blogger.com/profile/02347899306127799366</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>15</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7752976851994353052.post-5181991963952003385</id><published>2009-09-28T11:40:00.000-07:00</published><updated>2009-09-28T12:36:16.003-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='performance'/><category scheme='http://www.blogger.com/atom/ns#' term='disk io'/><category scheme='http://www.blogger.com/atom/ns#' term='write'/><category scheme='http://www.blogger.com/atom/ns#' term='mmap'/><category scheme='http://www.blogger.com/atom/ns#' term='fwrite'/><category scheme='http://www.blogger.com/atom/ns#' term='fread'/><title type='text'>mmap vs fread/fwrite  vs read/write</title><content type='html'>Disk read/write speeds are one of the important areas to be considered for performance improvements. Here is a small performance test that does some random read/writes on files and compared the results of mmap vs fread/fwrite vs read/write. The test goes like this &lt;br /&gt;"The program writes a record of length 256 bytes at location 0, 1024, 2048, .... up to 4 megabytes size file. Then the record returns to 256, 1280, 2304....and then 512, 1536, ... and then 768, 1792, ... (essentially 1K record split into 4 x 256 byte records, and written accessing randomly.) After writing the whole file, we read the whole file and re-write it sequentially as a copy"&lt;br /&gt;&lt;br /&gt;I tested the program with varying file sizes and the results are as shown.&lt;br /&gt;&lt;table border="1"&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;th&gt;File Size (in KB) ---&gt;&lt;/th&gt;&lt;br /&gt;&lt;th&gt;1&lt;/th&gt;&lt;br /&gt;&lt;th&gt;10&lt;/th&gt;&lt;br /&gt;&lt;th&gt;100&lt;/th&gt;&lt;br /&gt;&lt;th&gt;1024&lt;/th&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;fread/fwrite&lt;/td&gt;&lt;br /&gt;&lt;td&gt;0m0.005s&lt;/td&gt;&lt;br /&gt;&lt;td&gt;0m0.048s&lt;/td&gt;&lt;br /&gt;&lt;td&gt;0m6.219s&lt;/td&gt;&lt;br /&gt;&lt;td&gt;13m5.980s&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;read/write&lt;/td&gt;&lt;br /&gt;&lt;td&gt;0m0.007s&lt;/td&gt;&lt;br /&gt;&lt;td&gt;0m0.065s&lt;/td&gt;&lt;br /&gt;&lt;td&gt;0m5.491s&lt;/td&gt;&lt;br /&gt;&lt;td&gt;11m8.085s&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;mmap&lt;/td&gt;&lt;br /&gt;&lt;td&gt;0m0.003s&lt;/td&gt;&lt;br /&gt;&lt;td&gt;0m0.003s&lt;/td&gt;&lt;br /&gt;&lt;td&gt;0m0.020s&lt;/td&gt;&lt;br /&gt;&lt;td&gt;0m1.690s&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;/table&gt; &lt;br /&gt;&lt;br /&gt;And clearly the winner is mmap. It is one of most widely used options for fast disk I/O. In fact many database engines use this to achieve speed up. Hopefully I can use this properly in my database project, where we need to create a mini-database engine from scratch :-)&lt;br /&gt;&lt;br /&gt;The tests were run on virtual box debian guest running on windows xp host. The test files are attached &lt;a href="http://www.freewebs.com/shailesh/files/io_perf_tests.rar"&gt;here&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7752976851994353052-5181991963952003385?l=agenthunts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agenthunts.blogspot.com/feeds/5181991963952003385/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7752976851994353052&amp;postID=5181991963952003385' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/5181991963952003385'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/5181991963952003385'/><link rel='alternate' type='text/html' href='http://agenthunts.blogspot.com/2009/09/mmap-vs-freadfwrite-vs-readwrite.html' title='mmap vs fread/fwrite  vs read/write'/><author><name>AgentHunt</name><uri>http://www.blogger.com/profile/02347899306127799366</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7752976851994353052.post-5642785778686537468</id><published>2009-09-17T05:45:00.000-07:00</published><updated>2009-09-17T07:15:56.449-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='code reading'/><category scheme='http://www.blogger.com/atom/ns#' term='do something'/><category scheme='http://www.blogger.com/atom/ns#' term='best c codes'/><title type='text'>do something-2</title><content type='html'>Continuing on do something series, here is the second problem. The following C code snippet does something and we needed to figure out what it was doing . This was actually tougher than what the professor had given in the first class. &lt;br /&gt;The code goes like this&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;&lt;br /&gt;unsigned do_something(unsigned x,int p,int n,unsigned y)&lt;br /&gt;{&lt;br /&gt;        return x &amp;amp; ~(~(~0&amp;lt;&amp;lt;n)&amp;lt;&amp;lt;(p+1-n))&amp;#124;&lt;br /&gt;                (y&amp;amp; ~(~0&amp;lt;&amp;lt;n))&amp;lt;&amp;lt;(p+1-n);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Try your hands at this.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7752976851994353052-5642785778686537468?l=agenthunts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agenthunts.blogspot.com/feeds/5642785778686537468/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7752976851994353052&amp;postID=5642785778686537468' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/5642785778686537468'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/5642785778686537468'/><link rel='alternate' type='text/html' href='http://agenthunts.blogspot.com/2009/09/do-something-2.html' title='do something-2'/><author><name>AgentHunt</name><uri>http://www.blogger.com/profile/02347899306127799366</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7752976851994353052.post-4477359911124185238</id><published>2009-09-08T03:14:00.000-07:00</published><updated>2009-09-08T03:27:48.418-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='code reading'/><category scheme='http://www.blogger.com/atom/ns#' term='do something'/><category scheme='http://www.blogger.com/atom/ns#' term='best c codes'/><title type='text'>do something-1</title><content type='html'>I am taking a course this semester called Advanced operating systems. My professor who is an industry veteran has this habit of taking attendance by giving a short code reading test at the beginning of every class. The idea is actually not about attendance , but we get some exposure to complex and some of the best codes. The test involves some small C code which does something and we need to figure out what that code does in 5 minutes. Some of these codes are best ways to do something. Just have a look at the following code.&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;&lt;br /&gt;unsigned long do_something(unsigned n){&lt;br /&gt;    int i;&lt;br /&gt;    &lt;br /&gt;    for(i=0;n!=0;n&amp;amp;=n-1)&lt;br /&gt;        ++i;&lt;br /&gt;&lt;br /&gt;return i;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Explanation in the comments :-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7752976851994353052-4477359911124185238?l=agenthunts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agenthunts.blogspot.com/feeds/4477359911124185238/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7752976851994353052&amp;postID=4477359911124185238' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/4477359911124185238'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/4477359911124185238'/><link rel='alternate' type='text/html' href='http://agenthunts.blogspot.com/2009/09/do-something-1.html' title='do something-1'/><author><name>AgentHunt</name><uri>http://www.blogger.com/profile/02347899306127799366</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7752976851994353052.post-8431117122848895718</id><published>2009-09-01T12:02:00.000-07:00</published><updated>2009-09-01T12:13:38.804-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='handango'/><category scheme='http://www.blogger.com/atom/ns#' term='brainvita'/><category scheme='http://www.blogger.com/atom/ns#' term='Windows mobile'/><category scheme='http://www.blogger.com/atom/ns#' term='brain vita'/><category scheme='http://www.blogger.com/atom/ns#' term='Visual C++'/><category scheme='http://www.blogger.com/atom/ns#' term='directx'/><title type='text'>My first windows mobile game S^2 Brain vita</title><content type='html'>Finally, after a month of juggling around with visual studio 2008,directx and my ASUS-P527, I am done with my first windows mobile game. Normally my games used to have shabby graphics in my games due to my poor graphic making skills. So, never managed to publish any game. This time around (thanks to great looking graphics from my friend &lt;a href="http://sumanth.co.nr/"&gt;sumanth&lt;/a&gt;, we went a step ahead and put the game on sale on handango. Download &lt;a href="http://www.handango.com/catalog/ProductDetails.jsp?storeId=2218&amp;deviceId=2031&amp;platformId=30&amp;productId=256790"&gt;link&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Some screenshots of the game&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_dp950kxQnQk/Sp1xopxyB9I/AAAAAAAAAC0/78xMNqC2vJc/s1600-h/screen_shot_one.jpeg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 240px; height: 319px;" src="http://4.bp.blogspot.com/_dp950kxQnQk/Sp1xopxyB9I/AAAAAAAAAC0/78xMNqC2vJc/s400/screen_shot_one.jpeg" border="0" alt=""id="BLOGGER_PHOTO_ID_5376578473373599698" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_dp950kxQnQk/Sp1x2HGHwAI/AAAAAAAAAC8/zdWXo5djdUI/s1600-h/screen_shot_three.jpeg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 240px; height: 319px;" src="http://3.bp.blogspot.com/_dp950kxQnQk/Sp1x2HGHwAI/AAAAAAAAAC8/zdWXo5djdUI/s400/screen_shot_three.jpeg" border="0" alt=""id="BLOGGER_PHOTO_ID_5376578704581836802" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7752976851994353052-8431117122848895718?l=agenthunts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agenthunts.blogspot.com/feeds/8431117122848895718/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7752976851994353052&amp;postID=8431117122848895718' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/8431117122848895718'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/8431117122848895718'/><link rel='alternate' type='text/html' href='http://agenthunts.blogspot.com/2009/09/my-first-windows-mobile-game-s2-brain.html' title='My first windows mobile game S^2 Brain vita'/><author><name>AgentHunt</name><uri>http://www.blogger.com/profile/02347899306127799366</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_dp950kxQnQk/Sp1xopxyB9I/AAAAAAAAAC0/78xMNqC2vJc/s72-c/screen_shot_one.jpeg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7752976851994353052.post-3047631362335888071</id><published>2009-08-15T13:02:00.000-07:00</published><updated>2009-08-15T13:12:28.947-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='touch'/><category scheme='http://www.blogger.com/atom/ns#' term='Windows mobile'/><category scheme='http://www.blogger.com/atom/ns#' term='directdraw'/><category scheme='http://www.blogger.com/atom/ns#' term='Visual C++'/><title type='text'>Simple touch menu on windows mobile</title><content type='html'>This application demonstrates use of touch on windows mobile by creating a simple game menu and interacting with it.  Building on the directdraw features discussed in the previous two posts, we create simple game menu as shown.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_dp950kxQnQk/SocUuFpN2iI/AAAAAAAAACk/FmlzYOIJIKA/s1600-h/game_menu.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 263px; height: 400px;" src="http://3.bp.blogspot.com/_dp950kxQnQk/SocUuFpN2iI/AAAAAAAAACk/FmlzYOIJIKA/s400/game_menu.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5370283862684195362" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;We also go into full screen gaining exclusive access. The earlier app although covered the full screen, still some of the controls were getting activated behind the images. The problem there was that we were not using DDSCL_FULLSCREEN flag while creating the direct draw object. Also while experimenting with this app, there were problems using the window created by CreateWindow , instead had to use CreateWindowEx.  &lt;br /&gt;The menu screen is drawn on the surface “lpMenuBuffer” and is copied to “lpFrontBuffer” whenever required.  We also use another dummy screen to switch between menu controls using touch input.  The main idea how to deal with touch input is to handle the WM_LBUTTONDOWN message. This message is sent whenever there is a single tap on the screen. We handle this in the WndProc function. It is as shown.&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;case WM_LBUTTONDOWN:&lt;br /&gt;        printf(&amp;quot; button down\n&amp;quot;);&lt;br /&gt;        handle_input(LOWORD(lParam),HIWORD(lParam));&lt;br /&gt;        break;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The LOWORD macro retrieves the lower order WORD in the message paramenter “lParam”. This gives the x-coordinate of the click. Similarly, the HIWORD gives the y-coordinate of the click. These paramters are sent to the handle_input method is as shown below&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;void handle_input(int x,int y){&lt;br /&gt;    printf(&amp;quot;x,y=%d,%d\n&amp;quot;,x,y);&lt;br /&gt;    switch(game_state){&lt;br /&gt;        case GAME_MENU_STATE:&lt;br /&gt;            if(y&amp;gt;=40&amp;amp;&amp;amp;y&amp;lt;=(40+start_size.cy)){&lt;br /&gt;                int start_offset = (ScreenX-start_size.cx)/2;&lt;br /&gt;                if(x&amp;gt;=start_offset&amp;amp;&amp;amp;x&amp;lt;= (start_offset+start_size.cx)){&lt;br /&gt;                    printf(&amp;quot;Game running&amp;quot;);&lt;br /&gt;                    game_state = GAME_RUNNING_STATE;&lt;br /&gt;                    update_frame(lpThirdBuffer);&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            if(y&amp;gt;=80&amp;amp;&amp;amp;y&amp;lt;=(80+continue_size.cy)){&lt;br /&gt;                int continue_offset = (ScreenX-continue_size.cx)/2;&lt;br /&gt;                if(x&amp;gt;=continue_offset&amp;amp;&amp;amp;x&amp;lt;= (continue_offset+continue_size.cx)){&lt;br /&gt;                    printf(&amp;quot;Game running&amp;quot;);&lt;br /&gt;                    game_state = GAME_RUNNING_STATE;&lt;br /&gt;                    update_frame(lpThirdBuffer);&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            if(y&amp;gt;=120&amp;amp;&amp;amp;y&amp;lt;=(120+about_size.cy)){&lt;br /&gt;                int about_offset = (ScreenX-about_size.cx)/2;&lt;br /&gt;                if(x&amp;gt;=about_offset&amp;amp;&amp;amp;x&amp;lt;= (about_offset+about_size.cx)){&lt;br /&gt;                    printf(&amp;quot;about screen&amp;quot;);&lt;br /&gt;                    game_state = GAME_ABOUT_STATE;&lt;br /&gt;                    update_frame(lpThirdBuffer);&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            if(y&amp;gt;=160&amp;amp;&amp;amp;y&amp;lt;=(160+exit_size.cy)){&lt;br /&gt;                int exit_offset = (ScreenX-exit_size.cx)/2;&lt;br /&gt;                if(x&amp;gt;=exit_offset&amp;amp;&amp;amp;x&amp;lt;= (exit_offset+exit_size.cx)){&lt;br /&gt;                    printf(&amp;quot;Game exiting&amp;quot;);&lt;br /&gt;                    game_state = GAME_EXIT_STATE;&lt;br /&gt;                    handle_input(x,y);&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            break;&lt;br /&gt;        case GAME_ABOUT_STATE:&lt;br /&gt;            handle_back_button(x,y);&lt;br /&gt;            break;&lt;br /&gt;        case GAME_RUNNING_STATE:&lt;br /&gt;            handle_back_button(x,y);&lt;br /&gt;            break;&lt;br /&gt;        case GAME_EXIT_STATE:&lt;br /&gt;            release_resources();&lt;br /&gt;            SendMessage (main_window, WM_CLOSE, 0, 0);&lt;br /&gt;            PostQuitMessage(0);&lt;br /&gt;            break;&lt;br /&gt;        default:&lt;br /&gt;            PostQuitMessage(0);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The handle_input takes different actions based on (x,y) position and the state of the application. The (x,y) positions are matched with positions of the menu items and appropriate action taken.  Here, we just switch between the GAME_MENU and a dummy screen.  We move into dummy screen whenever the application is in GAME_MENU_STATE and it receives a touch/click input on any of the menu items. The dummy screen is as shown.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_dp950kxQnQk/SocVQS6UyeI/AAAAAAAAACs/DY15guTogt8/s1600-h/dummy_screen.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 255px; height: 400px;" src="http://3.bp.blogspot.com/_dp950kxQnQk/SocVQS6UyeI/AAAAAAAAACs/DY15guTogt8/s400/dummy_screen.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5370284450361166306" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;In all other states, whenever there is a click on the BACK button, it switches back to the GAME_MENU screen.  On the GAME_MENU screen, a click on the EXIT button, quits the application.&lt;br /&gt;The complete visual studio project is available for download from this &lt;a href="http://www.freewebs.com/shailesh/files/SimpleTouchMenu_16_08_2009.rar"&gt;link&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7752976851994353052-3047631362335888071?l=agenthunts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agenthunts.blogspot.com/feeds/3047631362335888071/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7752976851994353052&amp;postID=3047631362335888071' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/3047631362335888071'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/3047631362335888071'/><link rel='alternate' type='text/html' href='http://agenthunts.blogspot.com/2009/08/simple-touch-menu-on-windows-mobile.html' title='Simple touch menu on windows mobile'/><author><name>AgentHunt</name><uri>http://www.blogger.com/profile/02347899306127799366</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_dp950kxQnQk/SocUuFpN2iI/AAAAAAAAACk/FmlzYOIJIKA/s72-c/game_menu.png' height='72' width='72'/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7752976851994353052.post-1888328948389816543</id><published>2009-08-08T10:57:00.000-07:00</published><updated>2009-08-14T06:03:00.226-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows mobile'/><category scheme='http://www.blogger.com/atom/ns#' term='directdraw'/><category scheme='http://www.blogger.com/atom/ns#' term='Visual C++'/><category scheme='http://www.blogger.com/atom/ns#' term='directx'/><title type='text'>Add Image background with helloworld ticker on windows mobile</title><content type='html'>Continuing from the Hello world direct draw application, I modified the application to add a background image and hello world ticker. The idea here is to load a bitmap file and copy it to the directdraw surface and then blt the surface. Also we make the helloworld text tick around by setting up a timer  and vary the x position of the drawing at the timer intervals.  Quite strange errors like error 1814, error RC2135 kept popping up.  It was a little tricky to get it working.&lt;br /&gt;&lt;br /&gt;A new function load_bitmap has been newly added. The code is as follows&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;void load_bitmap(IDirectDrawSurface *pdds){&lt;br /&gt;    HINSTANCE hInstance = g_hInst;&lt;br /&gt;    HBITMAP hbm; //handle to a bit map&lt;br /&gt;    BITMAP bm;&lt;br /&gt;    HRESULT hr;&lt;br /&gt;    HDC hdcImage;&lt;br /&gt;    DDSURFACEDESC ddsd;&lt;br /&gt;    HDC hdc;&lt;br /&gt;&lt;br /&gt;    hbm = (HBITMAP) LoadImage(g_hInst, szBitmap, IMAGE_BITMAP, 0, 0, 0);&lt;br /&gt;    DWORD error = GetLastError();&lt;br /&gt;&lt;br /&gt;    error = GetLastError();&lt;br /&gt;    hdcImage = CreateCompatibleDC(NULL);&lt;br /&gt;    SelectObject(hdcImage,hbm);&lt;br /&gt;    GetObject(hbm, sizeof(bm), &amp;amp;bm);&lt;br /&gt;&lt;br /&gt;    //&lt;br /&gt;    // Get size of surface.&lt;br /&gt;    //&lt;br /&gt;    ddsd.dwSize = sizeof(ddsd);&lt;br /&gt;    ddsd.dwFlags = DDSD_HEIGHT &amp;#124; DDSD_WIDTH;&lt;br /&gt;    pdds-&amp;gt;GetSurfaceDesc(&amp;amp;ddsd);&lt;br /&gt;&lt;br /&gt;    if ((hr = pdds-&amp;gt;GetDC(&amp;amp;hdc)) == DD_OK) // gets the handle of the device context&lt;br /&gt;    {                                    // of the surface. &lt;br /&gt;        if (!StretchBlt(hdc,         //this draws the bitmap on the surface&lt;br /&gt;            0, 0,  &lt;br /&gt;            ddsd.dwWidth, &lt;br /&gt;            ddsd.dwHeight, &lt;br /&gt;            hdcImage, &lt;br /&gt;            0, 0,&lt;br /&gt;            bm.bmWidth, bm.bmHeight, &lt;br /&gt;            SRCCOPY)) hr = E_FAIL;&lt;br /&gt;        pdds-&amp;gt;ReleaseDC(hdc);&lt;br /&gt;    }&lt;br /&gt;    DeleteDC(hdcImage);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The important parts of the code are the LoadImage API call and the StretchBlt GDI call. The LoadImage loads a bitmap file and gets the handle hbm. The GetLastError() call was real handy in debugging the application. This call can fail with error 1814: The specified resource name cannot be found in the image file. Make sure the resource is added using the Add Resource Wizard. Since the LoadImage call takes a pointer to string which is the file name of the bitmap file, make sure you edit the name in the properties window of the resource. (shown in the below figure)&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_dp950kxQnQk/Sn2-ZiStKZI/AAAAAAAAACc/Nql-DdgV-Z4/s1600-h/edit_resource_name.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 250px;" src="http://3.bp.blogspot.com/_dp950kxQnQk/Sn2-ZiStKZI/AAAAAAAAACc/Nql-DdgV-Z4/s400/edit_resource_name.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5367655676806769042" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The “pdds” is a pointer to the directdrawsurface. The call pdds-&gt;GetHDC(&amp;hdc) gets the device context associated with the surface.  Onto this we use the StretchBlt GDI function to draw the bitmap loaded. This bitmap is available in the lpBackBuffer which is used later to draw the background image on the screen. Have used the Splash image from the Donuts example of the SDK samples.&lt;br /&gt;In case you are expermenting with adding/deleting resources, you may end up with errors like “error RC2135 : file not found”. In such situation , go to the resource view and delete the resource ids which are not used in the project.&lt;br /&gt;We setup the timer in the WM_PAINT case in the WndProc function.&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;// TODO: Add any drawing code here...&lt;br /&gt;        init_direct_draw(hWnd);&lt;br /&gt;        update_frame();&lt;br /&gt;        SetTimer(hWnd,WM_TIMER,100,NULL);&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This sends WM_TIMER message every 100ms, which is handled in the WM_TIMER case of the WndProc function. Here we call the update_frame(). So every 100ms , the background image is drawn on the screen. This is done by copying the backbuffer to frontBuffer. Also we draw the “Hello world” with different ‘x’ positions incrementing by 5 for every 100ms. We toggle the movement when it reaches the either ends. The update_frame() code is as shown below.&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;static void update_frame()&lt;br /&gt;{&lt;br /&gt;    HDC hdc;&lt;br /&gt;    int nMsg;&lt;br /&gt;    SIZE size;&lt;br /&gt;    DDBLTFX ddbltfx;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    RECT rc;&lt;br /&gt;    rc.left =0;&lt;br /&gt;    rc.top =0;&lt;br /&gt;    rc.bottom = ScreenY;&lt;br /&gt;    rc.right= ScreenX;&lt;br /&gt;    memset(&amp;amp;ddbltfx, 0, sizeof(ddbltfx));&lt;br /&gt;    ddbltfx.dwSize = sizeof(ddbltfx);&lt;br /&gt;&lt;br /&gt;    lpFrontBuffer-&amp;gt;Blt(&amp;amp;rc,lpBackBuffer,&amp;amp;rc,NULL,&amp;amp;ddbltfx);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    if(toggle == FALSE){&lt;br /&gt;        x = x + 5;&lt;br /&gt;        if(x&amp;gt;=ScreenX){&lt;br /&gt;            toggle = TRUE;&lt;br /&gt;        }&lt;br /&gt;    }else{&lt;br /&gt;        x = x -5;&lt;br /&gt;        if(x&amp;lt;=0){&lt;br /&gt;            toggle = FALSE;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    if (lpFrontBuffer-&amp;gt;GetDC(&amp;amp;hdc) == DD_OK)&lt;br /&gt;    {&lt;br /&gt;        SetTextColor(hdc, RGB(255, 0, 0));&lt;br /&gt;        nMsg = lstrlen(szMsg);&lt;br /&gt;        GetTextExtentPoint(hdc, szMsg, nMsg, &amp;amp;size);&lt;br /&gt;        ExtTextOut(hdc, &lt;br /&gt;            x,&lt;br /&gt;            y,&lt;br /&gt;            0,                        // fuOptions&lt;br /&gt;            NULL,                     // lprc&lt;br /&gt;            szMsg, &lt;br /&gt;            nMsg,&lt;br /&gt;            NULL);                    // lpDx&lt;br /&gt;        lpFrontBuffer-&amp;gt;ReleaseDC(hdc);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The complete visual studio project can be downloaded from the following &lt;a href="http://www.freewebs.com/shailesh/files/Image_Ticker_DirectDraw_08_08_2009.rar"&gt;link&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7752976851994353052-1888328948389816543?l=agenthunts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agenthunts.blogspot.com/feeds/1888328948389816543/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7752976851994353052&amp;postID=1888328948389816543' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/1888328948389816543'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/1888328948389816543'/><link rel='alternate' type='text/html' href='http://agenthunts.blogspot.com/2009/08/continuing-from-hello-world-direct-draw.html' title='Add Image background with helloworld ticker on windows mobile'/><author><name>AgentHunt</name><uri>http://www.blogger.com/profile/02347899306127799366</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_dp950kxQnQk/Sn2-ZiStKZI/AAAAAAAAACc/Nql-DdgV-Z4/s72-c/edit_resource_name.png' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7752976851994353052.post-352165668698569246</id><published>2009-08-07T04:30:00.001-07:00</published><updated>2009-08-08T07:34:40.199-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows mobile'/><category scheme='http://www.blogger.com/atom/ns#' term='directdraw'/><category scheme='http://www.blogger.com/atom/ns#' term='Visual C++'/><category scheme='http://www.blogger.com/atom/ns#' term='directx'/><title type='text'>A simple minimal directdraw hello world application for windows mobile</title><content type='html'>I wanted to build a simple game on my new ASUS-P527 windows mobile device. I started  putting the pieces together and I was almost done with the game logic. I was working on the command line until then and decided it was time for some graphics work. Being new to the windows  mobile platform started exploring the different options and boiled down to directx- directdraw. I searched for many tutorials and was really dissatisfied because I couldn't get a simple hello world application that I could get to working in minimum time. The samples provided in the windos mobile professional SDK didnt seem to work on the simulator. It started throwing up crazy errors and I thought I needed a much more simpler application to digest directdraw. Then on debugging and learning a bit of directx finally was able to get a hello world direct draw application working on my windows mobile phone. &lt;br /&gt;DirectDraw is the 2d component of Directx. Until then I had this wrong perception that Directx is only for 3D programming . Also I had heard about GDI which was mainly used in 2D graphics programming. &lt;br /&gt;The following is how I got my hello world direct draw application working. Some of the code is based on the samples provided with SDK and lot of error handling have been omitted for brevity.&lt;br /&gt;&lt;br /&gt; Use the Visual Studio Wizard to create a C++ Smart Device project and select Windows &lt;br /&gt;application. This will actually setup a simple window with OK, Help and About Menus. On &lt;br /&gt;executing this application will look something like this&lt;br /&gt; &lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_dp950kxQnQk/SnwQeHGwfNI/AAAAAAAAACM/QcJQLxHwr4o/s1600-h/hello_world_1.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 240px; height: 320px;" src="http://3.bp.blogspot.com/_dp950kxQnQk/SnwQeHGwfNI/AAAAAAAAACM/QcJQLxHwr4o/s400/hello_world_1.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5367182965408300242" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; We will add directdraw related code to the existing app to draw a hello world text. Before that make sure you add the "ddraw.lib" library in the Project Properteis-&gt;Configuration Properties-&gt; Linker-&gt;Input-&gt;Additional Dependencies.&lt;br /&gt;&lt;br /&gt;We will add two functions "init_direct_draw(HWND)" and the "update_frame()" to the existing code.&lt;br /&gt;The function init_direct_draw sets up and initializes the directdraw objects which we use it &lt;br /&gt;later in the update_frame() function. The code for init_direct_draw() is as below&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; &lt;br /&gt;&lt;br /&gt;background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: &lt;br /&gt;&lt;br /&gt;5px; overflow: auto; width: 100%"&gt;&lt;code&gt;void init_direct_draw(HWND hWnd){&lt;br /&gt;    DDCAPS          ddcaps;  //directdraw capabilities&lt;br /&gt;    HRESULT         ddrval; // directdraw return code&lt;br /&gt;    DDSURFACEDESC   ddsd;&lt;br /&gt;    DDSURFACEDESC   DDSurfDesc;&lt;br /&gt;    DDCAPS ddCaps;&lt;br /&gt;    DDCAPS ddHelCaps;&lt;br /&gt;&lt;br /&gt;    ddrval = DirectDrawCreate( NULL, &amp;amp;lpDD, NULL );&lt;br /&gt;    printf(&amp;quot;after creating DD object ddrval=%x&amp;quot;,ddrval);&lt;br /&gt;&lt;br /&gt;    ddrval = lpDD-&amp;gt;SetCooperativeLevel(hWnd , DDSCL_NORMAL );&lt;br /&gt;&lt;br /&gt;    //query for capabilities&lt;br /&gt;    lpDD-&amp;gt;GetCaps(&amp;amp;ddCaps, &amp;amp;ddHelCaps);&lt;br /&gt;    memset(&amp;amp;DDSurfDesc, 0, sizeof(DDSurfDesc));&lt;br /&gt;    DDSurfDesc.dwSize = sizeof(DDSurfDesc);&lt;br /&gt;&lt;br /&gt;    //get display mode&lt;br /&gt;    ddrval = lpDD-&amp;gt;GetDisplayMode(&amp;amp;DDSurfDesc );&lt;br /&gt;&lt;br /&gt;    ScreenX = DDSurfDesc.dwWidth;&lt;br /&gt;    ScreenY = DDSurfDesc.dwHeight;&lt;br /&gt;&lt;br /&gt;    // check the color key hardware capabilities&lt;br /&gt;    dwTransType = DDBLT_KEYSRC;&lt;br /&gt;    ddcaps.dwSize = sizeof( ddcaps );&lt;br /&gt;&lt;br /&gt;    // Create surfaces&lt;br /&gt;    memset( &amp;amp;ddsd, 0, sizeof( ddsd ) );&lt;br /&gt;    ddsd.dwSize = sizeof( ddsd );&lt;br /&gt;    ddsd.dwFlags = DDSD_CAPS;&lt;br /&gt;    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;&lt;br /&gt;    ddsd.dwWidth = ScreenX;&lt;br /&gt;    ddsd.dwHeight = ScreenY;&lt;br /&gt;&lt;br /&gt;    ddrval = lpDD-&amp;gt;CreateSurface( &amp;amp;ddsd, &amp;amp;lpFrontBuffer, NULL );&lt;br /&gt;    printf(&amp;quot;ddrval=%x&amp;quot;,ddrval);&lt;br /&gt;    ddsd.dwFlags = DDSD_WIDTH &amp;#124; DDSD_HEIGHT;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The following is a very brief description of what is happening in the init_direct_draw() &lt;br /&gt;function. More specific details are available at MSDN. The "lpDD" is a pointer to the DirectDraw object obtained by the function DirectDrawCreate. The option "DDSCL_NORMAL" specifies that the application will be a windowed application and not the full screen mode for which "DDSCL_FULLSCREEN" needs to be used. The ScreenX and ScreenY are the set to the screen sizes of the retrieved display mode. Directdraw uses the concept of surfaces  used to write on video memory which is actually displayed. Here one such surface is created called "lpFrontBuffer" using the "lpDD-&gt;CreateSurface" function. Whatever is written onto this surface can be used to display on the screen.&lt;br /&gt;&lt;br /&gt;The update_frame() code is as shown below.&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; &lt;br /&gt;&lt;br /&gt;background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: &lt;br /&gt;&lt;br /&gt;5px; overflow: auto; width: 100%"&gt;&lt;code&gt;static void update_frame()&lt;br /&gt;{&lt;br /&gt;    HDC hdc;&lt;br /&gt;    RECT rc;&lt;br /&gt;    int nMsg;&lt;br /&gt;    DDBLTFX ddbltfx;&lt;br /&gt;    SIZE size;&lt;br /&gt;&lt;br /&gt;    rc.left = 0;&lt;br /&gt;    rc.top = 25;&lt;br /&gt;    rc.bottom = ScreenY;&lt;br /&gt;    rc.right = ScreenX;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    // Use the blter to do a color fill to clear the back buffer&lt;br /&gt;    memset(&amp;amp;ddbltfx, 0, sizeof(ddbltfx));&lt;br /&gt;    ddbltfx.dwSize = sizeof(ddbltfx);&lt;br /&gt;    ddbltfx.dwFillColor = 120;//blue color&lt;br /&gt;    &lt;br /&gt;    lpFrontBuffer-&amp;gt;Blt(&amp;amp;rc, NULL, NULL, DDBLT_COLORFILL &amp;#124; DDBLT_WAITNOTBUSY, &lt;br /&gt;&lt;br /&gt;&amp;amp;ddbltfx);&lt;br /&gt;    if (lpFrontBuffer-&amp;gt;GetDC(&amp;amp;hdc) == DD_OK)&lt;br /&gt;    {&lt;br /&gt;        SetBkColor(hdc, RGB(0, 0, 0));&lt;br /&gt;        SetTextColor(hdc, RGB(255, 0, 0));&lt;br /&gt;&lt;br /&gt;             nMsg = lstrlen(szMsg);&lt;br /&gt;            GetTextExtentPoint(hdc, szMsg, nMsg, &amp;amp;size);&lt;br /&gt;        &lt;br /&gt;            ExtTextOut(hdc, &lt;br /&gt;               80,&lt;br /&gt;               40,&lt;br /&gt;               0,                        // fuOptions&lt;br /&gt;               NULL,                     // lprc&lt;br /&gt;               szMsg, &lt;br /&gt;               nMsg,&lt;br /&gt;               NULL);                    // lpDx&lt;br /&gt;   &lt;br /&gt;        lpFrontBuffer-&amp;gt;ReleaseDC(hdc);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This is the code used to draw the hello world text. The lpFrontBuffer which is the primary surface is filled with blue color for the dimensions occupied by the rectangle "rc". The Blt &lt;br /&gt;function is used to do that. (Blt and Flip main functions are key functions used to setup &lt;br /&gt;animation in directdraw). Then we use the ExtTexOut api to draw the "Hello world" at location 80,40 on the screen. Strictly speaking we aren't doing much with directdraw except to setup the minimum required objects and fill a rectangle with blue color. The hello world can be drawn without doing this setup and just using the non directdraw api such as the "ExtTextOut" functions. &lt;br /&gt;Add the two functions just below the line which says &lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; &lt;br /&gt;&lt;br /&gt;background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: &lt;br /&gt;&lt;br /&gt;5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&lt;br /&gt; // TODO: Add any drawing code here...&lt;br /&gt;init_direct_draw(hWnd);&lt;br /&gt;update_frame();&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Finally on execution , it looks something like this!!&lt;br /&gt; &lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_dp950kxQnQk/SnwQqHAd6eI/AAAAAAAAACU/FMzqWKO4aBU/s1600-h/hello_world_2.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 240px; height: 320px;" src="http://4.bp.blogspot.com/_dp950kxQnQk/SnwQqHAd6eI/AAAAAAAAACU/FMzqWKO4aBU/s400/hello_world_2.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5367183171540347362" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The required source files can be downloaded from this &lt;a href="http://www.freewebs.com/shailesh/files/HelloWorld_DirectDraw.rar"&gt;link&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7752976851994353052-352165668698569246?l=agenthunts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agenthunts.blogspot.com/feeds/352165668698569246/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7752976851994353052&amp;postID=352165668698569246' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/352165668698569246'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/352165668698569246'/><link rel='alternate' type='text/html' href='http://agenthunts.blogspot.com/2009/08/simple-minimal-directdraw-hello-world.html' title='A simple minimal directdraw hello world application for windows mobile'/><author><name>AgentHunt</name><uri>http://www.blogger.com/profile/02347899306127799366</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_dp950kxQnQk/SnwQeHGwfNI/AAAAAAAAACM/QcJQLxHwr4o/s72-c/hello_world_1.png' height='72' width='72'/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7752976851994353052.post-2212059440313607012</id><published>2008-09-29T19:40:00.000-07:00</published><updated>2009-08-07T04:29:34.791-07:00</updated><title type='text'>Hackintosh Macinspiron1525 Almost there!!!!!!</title><content type='html'>Last week I decided to play around with my dell inspiron 1525. Started installing iAtkos 4i (MAC OSX 10.5.4 Leopard for x86 hardware). The initial installation was smooth. I just followed the instructions available on many places on the web, mainly on the http://www.freewebs.com/bass-2k7.  Was very happy when I saw the Installation successful message, but happiness didnt last long though. When I restarted my system, I wasnt able to boot into mac at all. Hmm. There were lots of reasons why that happened . I had installed OSX on an extended partition and had not followed the instructions to install darwin bootloader.So I could boot only through the DVD with specifying the options rd=disk0s2.(here 2 refers to partition where I had installed).&lt;br /&gt;Second trial, logged onto windows, some neat partition magic tricks, converted the logical drive to primary partition and then installed OSX again. WOW, this time also successful and  I was happy as  I had heard lots of people face different kinds of problems. This time I did go through the following commands to install darwin bootloader&lt;br /&gt;fdisk -e /dev/rdisk0&lt;br /&gt;flag 2&lt;br /&gt;write&lt;br /&gt;update&lt;br /&gt;quit&lt;br /&gt;rebooted again. My system was able to boot with darwin bootloader but no luck this time also, it kept on crashing and rebooting. So put the DVD back again, and flagged my first primary partition again to boot my windows XP.&lt;br /&gt;On more googling came to know the CHAIN0 file which actually can boot off a OSX from NTBDLR of windows. Some copied the file from the DVD and made an entry into boot.ini file. Tried booting this time again. Chain0 file is able to detect HFS+ partition and load the darwin bootloader but again same problem it kept crashing and rebooting.&lt;br /&gt;For time being I am able to boot into  OSX using the DVD only. Need to get a workaround on this.&lt;br /&gt;Hmmm... Hackintosh Macinspiron1525 Almost there!!!!!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7752976851994353052-2212059440313607012?l=agenthunts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agenthunts.blogspot.com/feeds/2212059440313607012/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7752976851994353052&amp;postID=2212059440313607012' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/2212059440313607012'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/2212059440313607012'/><link rel='alternate' type='text/html' href='http://agenthunts.blogspot.com/2008/09/hackintosh-macinspiron1525-almost-there.html' title='Hackintosh Macinspiron1525 Almost there!!!!!!'/><author><name>AgentHunt</name><uri>http://www.blogger.com/profile/02347899306127799366</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7752976851994353052.post-8218251787177769865</id><published>2008-08-03T04:24:00.000-07:00</published><updated>2009-08-07T04:27:08.498-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='vedic maths'/><title type='text'>Vedic Mathematics tips and tricks</title><content type='html'>Was just browsing about vedic mathematics and came across some cool vedic mathematic tips&lt;br /&gt;&lt;br /&gt;http://www.streetdirectory.com/travel_guide/62281/education/vedic_mathematics_in_a_nutshell.html&lt;br /&gt;&lt;br /&gt;Here he talks about multiplying two numbers that end with number 5 and their difference is 10.&lt;br /&gt;He takes the example&lt;br /&gt;35x45 and uses the procedure i.e&lt;br /&gt; [Ten's digit of first number]x[1+ Ten's digit of second number]&lt;br /&gt;3 x [1+4] = 15.&lt;br /&gt;Just append 75 to the above number and  you get the answer 1575 which infact is what you get when you multiply 35x45.&lt;br /&gt;But I guess there are small subtle rules to be considered while multiplying the numbers like above.&lt;br /&gt;&lt;br /&gt;because consider 45x35&lt;br /&gt; 4x[1+3] = 16&lt;br /&gt;and the answer would be 1675 which is not correct.&lt;br /&gt;&lt;br /&gt;Possibly the rule could be that the first number considered has to be smaller.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7752976851994353052-8218251787177769865?l=agenthunts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agenthunts.blogspot.com/feeds/8218251787177769865/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7752976851994353052&amp;postID=8218251787177769865' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/8218251787177769865'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/8218251787177769865'/><link rel='alternate' type='text/html' href='http://agenthunts.blogspot.com/2008/08/vedic-mathematics-tips-and-tricks.html' title='Vedic Mathematics tips and tricks'/><author><name>AgentHunt</name><uri>http://www.blogger.com/profile/02347899306127799366</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7752976851994353052.post-200086479557933265</id><published>2008-05-22T01:45:00.000-07:00</published><updated>2008-05-22T05:27:05.473-07:00</updated><title type='text'>SRM 401,DreamingAboutCarrots</title><content type='html'>The problem boils down to finding out number of integer points between the two points (x1,y1) and (x2,y2). One way to solve is the brute force, write the equation of a line (y2-y)/(y2-y1) = (x2-x)/(x2-x1) and test the number of (x,y) values that satisfy the equation. Need to make sure for odd cases like 0/0 and x1&gt;x2 and y1&gt;y2 cases. &lt;br /&gt;&lt;br /&gt;I was browsing through my fellow coder's solutions and lots of people with a good number theory knowledge had a pretty simple solution. The solution comes from the statement that "The number of integer points on a line segment joining origin and a point (a,b) is gcd(a,b)+1". A slight variation of the above statement becomes "The number of integer points on a line segment joining points(x1,y1) and (x2,y2) is gcd(x2-x1,y2-y1)+1".&lt;br /&gt;&lt;br /&gt;The proof of this statement is as follows&lt;br /&gt; We know that the equation of a line is y = mx + c, where m is the slope of the line and c is the y intercept of the line.&lt;br /&gt;Let us consider a point (a,b) and line passing through the origin. So the equation becomes y = b/a*x. 'c' becomes 0 since the line passes through the origin and y intercept becomes 0.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;Let d be the gcd of the numbers a and b. i.e d = gcd(a,b)&lt;br /&gt;The number of integers x such that y=b/a*x is also integer 0&amp;lt;=x&amp;lt;=a is&lt;br /&gt;number of integers in the progression (0,a/d,2a/d,........(d-1)a/d,a). Using the arithmetic progression formula&lt;br /&gt;   T(n) = a + (n-1)*f ,here 'f' is the common difference in the progression&lt;br /&gt;   a  =   0 + (n-1)*a/d&lt;br /&gt;   d = n-1&lt;br /&gt;   n  = d+1&lt;br /&gt; i.e n = gcd(a,b)+1&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;A variation of this when two points are given is that the origin being offset to a point say (p,q). In that case it becomes, n = gcd(a-p,b-q)+1.  or if the points are (x1,y1) and (x2,y2) , then solution becomes gcd(x2-x1,y2-y1)+1&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7752976851994353052-200086479557933265?l=agenthunts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agenthunts.blogspot.com/feeds/200086479557933265/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7752976851994353052&amp;postID=200086479557933265' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/200086479557933265'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/200086479557933265'/><link rel='alternate' type='text/html' href='http://agenthunts.blogspot.com/2008/05/srm-401dreamingaboutcarrots.html' title='SRM 401,DreamingAboutCarrots'/><author><name>AgentHunt</name><uri>http://www.blogger.com/profile/02347899306127799366</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7752976851994353052.post-7293218576553155316</id><published>2008-03-24T03:08:00.000-07:00</published><updated>2008-03-24T03:51:31.459-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><category scheme='http://www.blogger.com/atom/ns#' term='openGL'/><title type='text'>Was trying my hands at openGL...</title><content type='html'>I was trying my hands at openGL and came across a very good jumpstart tutorials at &lt;a href="http://www.cprogramming.com/tutorial/opengl_first_opengl_program.html"&gt;http://www.cprogramming.com/tutorial/opengl_first_opengl_program.html&lt;/a&gt;.&lt;br /&gt;After going through the basics, couldn't wait to get some action going on. Created a new project in visual C++ 2008 Express Edition. Copy pasted the code in the above link ;-). On compilation was the following errors&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;1&amp;gt;------ Build started: Project: FirstOpenGL, Configuration: Debug Win32 ------&lt;br /&gt;1&amp;gt;Compiling...&lt;br /&gt;1&amp;gt;Main.cpp&lt;br /&gt;1&amp;gt;e:\installations\visualstudioprojects\firstopengl\firstopengl\main.cpp(31) : fatal error C1083: Cannot open include file: 'gl/glaux.h': No such file or directory&lt;br /&gt;1&amp;gt;Build log was saved at &amp;quot;file://e:\installations\VisualStudioProjects\FirstOpenGL\FirstOpenGL\Debug\BuildLog.htm&amp;quot;&lt;br /&gt;1&amp;gt;FirstOpenGL - 1 error(s), 0 warning(s)&lt;br /&gt;========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;On googling found out that "glaux.h" has been deprecated. So removed the header file and F7.&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;1&amp;gt;------ Build started: Project: FirstOpenGL, Configuration: Debug Win32 ------&lt;br /&gt;1&amp;gt;Compiling...&lt;br /&gt;1&amp;gt;Main.cpp&lt;br /&gt;1&amp;gt;e:\installations\visualstudioprojects\firstopengl\firstopengl\main.cpp(565) : error C2440: '=' : cannot convert from 'const char [8]' to 'LPCWSTR'&lt;br /&gt;1&amp;gt;        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast&lt;br /&gt;1&amp;gt;e:\installations\visualstudioprojects\firstopengl\firstopengl\main.cpp(589) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [20]' to 'LPCWSTR'&lt;br /&gt;1&amp;gt;        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast&lt;br /&gt;1&amp;gt;e:\installations\visualstudioprojects\firstopengl\firstopengl\main.cpp(622) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [8]' to 'LPCWSTR'&lt;br /&gt;1&amp;gt;        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast&lt;br /&gt;1&amp;gt;Build log was saved at &amp;quot;file://e:\installations\VisualStudioProjects\FirstOpenGL\FirstOpenGL\Debug\BuildLog.htm&amp;quot;&lt;br /&gt;1&amp;gt;FirstOpenGL - 3 error(s), 0 warning(s)&lt;br /&gt;========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The above error usually occurs when unicode character set is used. There were different solutions available on different forums. The easiest one I found was to change the Properties-&gt;General-&gt;Character Set to Use Multi-Byte Character Set.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_dp950kxQnQk/R-eCMur1rgI/AAAAAAAAAAs/BaCpf8MTUGM/s1600-h/ChangeCharacterSet.gif"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://1.bp.blogspot.com/_dp950kxQnQk/R-eCMur1rgI/AAAAAAAAAAs/BaCpf8MTUGM/s400/ChangeCharacterSet.gif" border="0" alt=""id="BLOGGER_PHOTO_ID_5181253051514990082" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;F7 again......&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;1&amp;gt;------ Build started: Project: FirstOpenGL, Configuration: Debug Win32 ------&lt;br /&gt;1&amp;gt;Compiling...&lt;br /&gt;1&amp;gt;Main.cpp&lt;br /&gt;1&amp;gt;Compiling manifest to resources...&lt;br /&gt;1&amp;gt;Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0&lt;br /&gt;1&amp;gt;Copyright (C) Microsoft Corporation.  All rights reserved.&lt;br /&gt;1&amp;gt;Linking...&lt;br /&gt;1&amp;gt;Main.obj : error LNK2019: unresolved external symbol __imp__glPopMatrix@0 referenced in function &amp;quot;void __cdecl DrawCube(float,float,float)&amp;quot; (?DrawCube@@YAXMMM@Z)&lt;br /&gt;1&amp;gt;Main.obj : error LNK2019: unresolved external symbol __imp__glEnd@0 referenced in function &amp;quot;void __cdecl DrawCube(float,float,float)&amp;quot; (?DrawCube@@YAXMMM@Z)&lt;br /&gt;1&amp;gt;Main.obj : error LNK2019: unresolved external symbol __imp__glVertex3f@12 referenced in function &amp;quot;void __cdecl DrawCube(float,float,float)&amp;quot; (?DrawCube@@YAXMMM@Z)&lt;br /&gt;1&amp;gt;Main.obj : error LNK2019: unresolved external symbol __imp__glBegin@4 referenced in function &amp;quot;void __cdecl DrawCube(float,float,float)&amp;quot; (?DrawCube@@YAXMMM@Z)&lt;br /&gt;1&amp;gt;Main.obj : error LNK2019: unresolved external symbol __imp__glPushMatrix@0 referenced in function &amp;quot;void __cdecl DrawCube(float,float,float)&amp;quot; (?DrawCube@@YAXMMM@Z)&lt;br /&gt;1&amp;gt;Main.obj : error LNK2019: unresolved external symbol __imp__glScalef@12 referenced in function &amp;quot;void __cdecl DrawArm(float,float,float)&amp;quot; (?DrawArm@@YAXMMM@Z)&lt;br /&gt;1&amp;gt;Main.obj : error LNK2019: unresolved external symbol __imp__glTranslatef@12 referenced in function &amp;quot;void __cdecl DrawArm(float,float,float)&amp;quot; (?DrawArm@@YAXMMM@Z)&lt;br /&gt;1&amp;gt;Main.obj : error LNK2019: unresolved external symbol __imp__glColor3f@12 referenced in function &amp;quot;void __cdecl DrawArm(float,float,float)&amp;quot; (?DrawArm@@YAXMMM@Z)&lt;br /&gt;1&amp;gt;Main.obj : error LNK2019: unresolved external symbol __imp__glRotatef@16 referenced in function &amp;quot;void __cdecl DrawRobot(float,float,float)&amp;quot; (?DrawRobot@@YAXMMM@Z)&lt;br /&gt;1&amp;gt;Main.obj : error LNK2019: unresolved external symbol __imp__glFlush@0 referenced in function &amp;quot;void __cdecl Render(void)&amp;quot; (?Render@@YAXXZ)&lt;br /&gt;1&amp;gt;Main.obj : error LNK2019: unresolved external symbol __imp__glLoadIdentity@0 referenced in function &amp;quot;void __cdecl Render(void)&amp;quot; (?Render@@YAXXZ)&lt;br /&gt;1&amp;gt;Main.obj : error LNK2019: unresolved external symbol __imp__glClear@4 referenced in function &amp;quot;void __cdecl Render(void)&amp;quot; (?Render@@YAXXZ)&lt;br /&gt;1&amp;gt;Main.obj : error LNK2019: unresolved external symbol __imp__glClearColor@16 referenced in function &amp;quot;void __cdecl Render(void)&amp;quot; (?Render@@YAXXZ)&lt;br /&gt;1&amp;gt;Main.obj : error LNK2019: unresolved external symbol __imp__glEnable@4 referenced in function &amp;quot;void __cdecl Render(void)&amp;quot; (?Render@@YAXXZ)&lt;br /&gt;1&amp;gt;Main.obj : error LNK2019: unresolved external symbol _gluPerspective@32 referenced in function &amp;quot;long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)&amp;quot; (?WndProc@@YGJPAUHWND__@@IIJ@Z)&lt;br /&gt;1&amp;gt;Main.obj : error LNK2019: unresolved external symbol __imp__glMatrixMode@4 referenced in function &amp;quot;long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)&amp;quot; (?WndProc@@YGJPAUHWND__@@IIJ@Z)&lt;br /&gt;1&amp;gt;Main.obj : error LNK2019: unresolved external symbol __imp__glViewport@16 referenced in function &amp;quot;long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)&amp;quot; (?WndProc@@YGJPAUHWND__@@IIJ@Z)&lt;br /&gt;1&amp;gt;Main.obj : error LNK2019: unresolved external symbol __imp__wglDeleteContext@4 referenced in function &amp;quot;long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)&amp;quot; (?WndProc@@YGJPAUHWND__@@IIJ@Z)&lt;br /&gt;1&amp;gt;Main.obj : error LNK2019: unresolved external symbol __imp__wglMakeCurrent@8 referenced in function &amp;quot;long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)&amp;quot; (?WndProc@@YGJPAUHWND__@@IIJ@Z)&lt;br /&gt;1&amp;gt;Main.obj : error LNK2019: unresolved external symbol __imp__wglCreateContext@4 referenced in function &amp;quot;long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)&amp;quot; (?WndProc@@YGJPAUHWND__@@IIJ@Z)&lt;br /&gt;1&amp;gt;E:\installations\VisualStudioProjects\FirstOpenGL\Debug\FirstOpenGL.exe : fatal error LNK1120: 20 unresolved externals&lt;br /&gt;1&amp;gt;Build log was saved at &amp;quot;file://e:\installations\VisualStudioProjects\FirstOpenGL\FirstOpenGL\Debug\BuildLog.htm&amp;quot;&lt;br /&gt;1&amp;gt;FirstOpenGL - 21 error(s), 0 warning(s)&lt;br /&gt;========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;All linking errors probably due to missing openGL libraries.&lt;br /&gt;Added openGL32.lib in Properties-&gt;Linker-&gt;Input.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_dp950kxQnQk/R-eEF-r1rhI/AAAAAAAAAA0/hwW5h0yrAHU/s1600-h/LinkOpenGL32lib.gif"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://2.bp.blogspot.com/_dp950kxQnQk/R-eEF-r1rhI/AAAAAAAAAA0/hwW5h0yrAHU/s400/LinkOpenGL32lib.gif" border="0" alt=""id="BLOGGER_PHOTO_ID_5181255134574128658" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;F7 again...&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;1&amp;gt;------ Build started: Project: FirstOpenGL, Configuration: Debug Win32 ------&lt;br /&gt;1&amp;gt;Linking...&lt;br /&gt;1&amp;gt;Main.obj : error LNK2019: unresolved external symbol _gluPerspective@32 referenced in function &amp;quot;long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)&amp;quot; (?WndProc@@YGJPAUHWND__@@IIJ@Z)&lt;br /&gt;1&amp;gt;E:\installations\VisualStudioProjects\FirstOpenGL\Debug\FirstOpenGL.exe : fatal error LNK1120: 1 unresolved externals&lt;br /&gt;1&amp;gt;Build log was saved at &amp;quot;file://e:\installations\VisualStudioProjects\FirstOpenGL\FirstOpenGL\Debug\BuildLog.htm&amp;quot;&lt;br /&gt;1&amp;gt;FirstOpenGL - 2 error(s), 0 warning(s)&lt;br /&gt;========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;One more linking error a different library missing. It seems that "gluPerspective" function definition is found in "glu32.lib". Added that to the properties as above.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_dp950kxQnQk/R-eFUOr1riI/AAAAAAAAAA8/qiaNDhFAen8/s1600-h/glu32lib.gif"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://3.bp.blogspot.com/_dp950kxQnQk/R-eFUOr1riI/AAAAAAAAAA8/qiaNDhFAen8/s400/glu32lib.gif" border="0" alt=""id="BLOGGER_PHOTO_ID_5181256478898892322" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;F7 again... and whooah successful :-)&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;1&amp;gt;------ Build started: Project: FirstOpenGL, Configuration: Debug Win32 ------&lt;br /&gt;1&amp;gt;Linking...&lt;br /&gt;1&amp;gt;Embedding manifest...&lt;br /&gt;1&amp;gt;Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0&lt;br /&gt;1&amp;gt;Copyright (C) Microsoft Corporation.  All rights reserved.&lt;br /&gt;1&amp;gt;Build log was saved at &amp;quot;file://e:\installations\VisualStudioProjects\FirstOpenGL\FirstOpenGL\Debug\BuildLog.htm&amp;quot;&lt;br /&gt;1&amp;gt;FirstOpenGL - 0 error(s), 0 warning(s)&lt;br /&gt;========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Ctrl+F5 and there was this dancing robot.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_dp950kxQnQk/R-eGDur1rjI/AAAAAAAAABE/HtiQBkKexHo/s1600-h/dancingrobot.gif"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://1.bp.blogspot.com/_dp950kxQnQk/R-eGDur1rjI/AAAAAAAAABE/HtiQBkKexHo/s400/dancingrobot.gif" border="0" alt=""id="BLOGGER_PHOTO_ID_5181257294942678578" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Hmm... I wish I had got the code working before doing some googling for solutions in different forums. ;-) Hehe. Anyways just thought will document at one place :-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7752976851994353052-7293218576553155316?l=agenthunts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agenthunts.blogspot.com/feeds/7293218576553155316/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7752976851994353052&amp;postID=7293218576553155316' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/7293218576553155316'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/7293218576553155316'/><link rel='alternate' type='text/html' href='http://agenthunts.blogspot.com/2008/03/was-trying-my-hands-at-opengl.html' title='Was trying my hands at openGL...'/><author><name>AgentHunt</name><uri>http://www.blogger.com/profile/02347899306127799366</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_dp950kxQnQk/R-eCMur1rgI/AAAAAAAAAAs/BaCpf8MTUGM/s72-c/ChangeCharacterSet.gif' height='72' width='72'/><thr:total>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7752976851994353052.post-5838911470033578598</id><published>2008-02-07T11:23:00.000-08:00</published><updated>2008-02-07T11:34:01.364-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Generating Subsets of a set</title><content type='html'>It happens so many times that you need to generate all the subsets of a set and then analyze those subsets to solve a problem. One of the ways to generate is using a binary mask.(counter). A set of size 'n' has 2^n subsets.  The following code generates all the subsets.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt; public int[][] generateSubSet(int[] set) {&lt;br /&gt;  int n = set.length;&lt;br /&gt;  int len = (int) Math.pow(2, n);&lt;br /&gt;  int[][] res = new int[len][n];&lt;br /&gt;  for (int i = 0; i &lt; len; i++) {&lt;br /&gt;   String s = Integer.toBinaryString(i);&lt;br /&gt;   int sLen = s.length();&lt;br /&gt;   for (int j = 0; j &lt; n - sLen; j++) {&lt;br /&gt;    s = "0" + s;&lt;br /&gt;   }&lt;br /&gt;   ArrayList&lt;Integer&gt; list = new ArrayList&lt;Integer&gt;();&lt;br /&gt;   for (int j = 0; j &lt; s.length(); j++) {&lt;br /&gt;    int tmp = Integer.parseInt("" + s.charAt(j));&lt;br /&gt;    if(tmp==1){&lt;br /&gt;      list.add(set[j]);&lt;br /&gt;    }&lt;br /&gt;   }&lt;br /&gt;   res[i] = new int[list.size()];&lt;br /&gt;   Integer[] arr = (Integer[])list.toArray(new Integer[0]);&lt;br /&gt;   for (int j = 0; j &lt; arr.length; j++) {&lt;br /&gt;    res[i][j] = arr[j].intValue();&lt;br /&gt;   }&lt;br /&gt;   System.out.println(Arrays.toString(res[i]));&lt;br /&gt;  }&lt;br /&gt;  return res;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For the set {1,2,3}, the following are the subsets&lt;br /&gt;[]&lt;br /&gt;[3]&lt;br /&gt;[2]&lt;br /&gt;[2, 3]&lt;br /&gt;[1]&lt;br /&gt;[1, 3]&lt;br /&gt;[1, 2]&lt;br /&gt;[1, 2, 3]&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7752976851994353052-5838911470033578598?l=agenthunts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agenthunts.blogspot.com/feeds/5838911470033578598/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7752976851994353052&amp;postID=5838911470033578598' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/5838911470033578598'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/5838911470033578598'/><link rel='alternate' type='text/html' href='http://agenthunts.blogspot.com/2008/02/generating-subsets-of-set.html' title='Generating Subsets of a set'/><author><name>AgentHunt</name><uri>http://www.blogger.com/profile/02347899306127799366</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7752976851994353052.post-5461643178371268016</id><published>2008-02-05T10:30:00.000-08:00</published><updated>2008-02-05T10:44:59.243-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Topcoder'/><title type='text'>SRM 390</title><content type='html'>After really long time ,took part in topcoder contest (SRM390). although I suck big time at it ;-). Anyways there was an interesting problem about ConcatenateNumber. Very tricky problem. The normal brute force solution always exceed more than 2sec to solve.  After trying out different solutions and learning some interesting properties about divisibility,[You can always replace a few digits in a number by the remainder you get when you divide those digits by the divisor]   &lt;a href="http://mathforum.org/k12/mathtips/ward3.html"&gt;http://mathforum.org/k12/mathtips/ward3.html&lt;/a&gt; (See the last section on modular arithmetic), came up with the following solution.&lt;br /&gt;&lt;br /&gt;public int getSmallest(int number, int k) {&lt;br /&gt;       long n = number;&lt;br /&gt;       String t = Integer.toString(number);&lt;br /&gt;       String s = Long.toString(n);&lt;br /&gt;       int count = 1;&lt;br /&gt;       if (k % 2 == 0 &amp;amp;&amp;amp; number % 2 == 1) {&lt;br /&gt;           return -1;&lt;br /&gt;       }&lt;br /&gt;       while (count&lt;100000) {&lt;br /&gt;           long rem = n % k;&lt;br /&gt;           if (rem == 0) {&lt;br /&gt;               return count;&lt;br /&gt;           }&lt;br /&gt;           count++;&lt;br /&gt;           s = Long.toString(rem) + t;&lt;br /&gt;           n = Long.parseLong(s);&lt;br /&gt;       }&lt;br /&gt;       return -1;&lt;br /&gt;   }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7752976851994353052-5461643178371268016?l=agenthunts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agenthunts.blogspot.com/feeds/5461643178371268016/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7752976851994353052&amp;postID=5461643178371268016' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/5461643178371268016'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/5461643178371268016'/><link rel='alternate' type='text/html' href='http://agenthunts.blogspot.com/2008/02/srm-390.html' title='SRM 390'/><author><name>AgentHunt</name><uri>http://www.blogger.com/profile/02347899306127799366</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7752976851994353052.post-5671530096128994267</id><published>2008-02-01T06:17:00.001-08:00</published><updated>2008-02-01T06:41:55.809-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><title type='text'>Building openJDK on windows</title><content type='html'>It's been quite some while I've been wanting to do build openJDK. But couldnt find much my time. Somehow managed to squeeze some time. I had downloaded openJDK bundle long time ago and was just lying on some drive on my system.&lt;br /&gt;Did read lots of posts of the net about not to use visual studio versions greater than 2003. But since visual studio 2008 beta2 was already available on my system, I went ahead with it. But it was a bad choice :-).&lt;br /&gt;Started off with hotspot JVM build.&lt;br /&gt;Anyways following are the steps which I followed and landed up the errors.&lt;br /&gt;1)  Visual studio 2008 beta2 installed.&lt;br /&gt;2) Cygwin installed.&lt;br /&gt;3) openJDK downloaded&lt;br /&gt;4) JDK6 installed.&lt;br /&gt;5) Set        ALT_JDK_IMPORT_PATH=JAVA_HOME(JDK6 installation directory)&lt;br /&gt;6) Opened a cmd prompt and set the visual studio environment variables by running the vsvars32.bat&lt;br /&gt;7) Start cygwin using cygwin.bat&lt;br /&gt;8) cd 'ed to make directory of hotspot&lt;br /&gt;9) make -f Makefile&lt;br /&gt;&lt;br /&gt;Uffh. Ended with the following errors&lt;br /&gt;&lt;br /&gt;       E:\VisualStudio\VC\INCLUDE\string.h(74) : see declaration of 'strcpy'&lt;br /&gt;g:\downloads\javasrc\openjdk-7-ea-src-b23-30_oct_2007\openjdk\hotspot\src\share\&lt;br /&gt;vm\adlc\output_c.cpp(1250) : warning C4996: 'sprintf': This function or variable&lt;br /&gt;may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _C&lt;br /&gt;RT_SECURE_NO_WARNINGS. See online help for details.&lt;br /&gt;       E:\VisualStudio\VC\INCLUDE\stdio.h(366) : see declaration of 'sprintf'&lt;br /&gt;g:\downloads\javasrc\openjdk-7-ea-src-b23-30_oct_2007\openjdk\hotspot\src\share\&lt;br /&gt;vm\adlc\output_c.cpp(1252) : warning C4996: 'strcpy': This function or variable&lt;br /&gt;may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT&lt;br /&gt;_SECURE_NO_WARNINGS. See online help for details.&lt;br /&gt;       E:\VisualStudio\VC\INCLUDE\string.h(74) : see declaration of 'strcpy'&lt;br /&gt;Generating Code...&lt;br /&gt;NMAKE : fatal error U1077: 'e:\VisualStudio\VC\BIN\cl.exe' : return code '0x2'&lt;br /&gt;Stop.&lt;br /&gt;NMAKE : fatal error U1077: 'cd' : return code '0x2'&lt;br /&gt;Stop.&lt;br /&gt;NMAKE : fatal error U1077: 'e:\VisualStudio\VC\BIN\nmake.EXE' : return code '0x2&lt;br /&gt;'&lt;br /&gt;Stop.&lt;br /&gt;make[1]: *** [generic_build2] Error 2&lt;br /&gt;make[1]: Leaving directory `/cygdrive/g/downloads/javasrc/openjdk-7-ea-src-b23-3&lt;br /&gt;0_oct_2007/openjdk/hotspot/make'&lt;br /&gt;make: *** [product] Error 2&lt;br /&gt;&lt;br /&gt;google search doesnt seem to help me much and also being a Makefile newbie :-)&lt;br /&gt;&lt;br /&gt;Hm... giving a break. will come back later on this.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7752976851994353052-5671530096128994267?l=agenthunts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agenthunts.blogspot.com/feeds/5671530096128994267/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7752976851994353052&amp;postID=5671530096128994267' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/5671530096128994267'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/5671530096128994267'/><link rel='alternate' type='text/html' href='http://agenthunts.blogspot.com/2008/02/building-openjdk-on-windows.html' title='Building openJDK on windows'/><author><name>AgentHunt</name><uri>http://www.blogger.com/profile/02347899306127799366</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7752976851994353052.post-8136352281633631396</id><published>2008-01-23T10:23:00.000-08:00</published><updated>2009-08-07T04:18:18.498-07:00</updated><title type='text'>Creating scrolling images J2ME</title><content type='html'>Often in 2D games, there is a need for scrolling backgrounds. Either  a race track or river etc.&lt;br /&gt;Here we see how to do it using MIDP2.0 game API.&lt;br /&gt;&lt;br /&gt;Consider a top down racing game. Usually the road or track needs to be scrolling which gives the effect as though you are moving ahead. To do it this what we do is draw the image of the road in such a way that it gives the scrolling effect. Given below is an image of road or a track.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_dp950kxQnQk/R5eKfv_UQRI/AAAAAAAAAAM/qNdhDVMg2cg/s1600-h/track.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://4.bp.blogspot.com/_dp950kxQnQk/R5eKfv_UQRI/AAAAAAAAAAM/qNdhDVMg2cg/s320/track.png" alt="" id="BLOGGER_PHOTO_ID_5158744176238805266" border="0"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Firstly scale the image to the required dimensions usually to cover the complete screen. Next draw the image from the origin something like the following code&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;g.drawImage(track,0,0,getWidth(),getHeight();&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;To scroll this image, when user hits the up arrow,clear the screen and draw the image starting from the next row.&lt;br /&gt;&lt;br /&gt;       &lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt; //code to clear the screen&lt;br /&gt;        g.drawImage(track,1,1,getWidth(),getHeight(); &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;To do this we use a variable and update this whenever the user presses the up arrow.The code snippet will be something like this&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;    public void drawScreen(){&lt;br /&gt;        g.setColor(255,255,255);&lt;br /&gt;        g.fillRect(0,0,getWidth(),getHeight());&lt;br /&gt;        g.drawImage(img,imgX,imgY,Graphics.TOP&amp;#124;Graphics.LEFT);&lt;br /&gt;        flushGraphics();&lt;br /&gt;    }&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;This will look something like this.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_dp950kxQnQk/R8PejHun69I/AAAAAAAAAAU/azr5ly9oYCA/s1600-h/scroller_1.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://1.bp.blogspot.com/_dp950kxQnQk/R8PejHun69I/AAAAAAAAAAU/azr5ly9oYCA/s320/scroller_1.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5171221492102851538" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Although there is scrolling effect, this is not exactly what we want, the screen gets blank as we scroll ahead. Now we draw the image again, this time we start from the negative height of the screen. And as we moved ahead, we keep drawing that at one row    higher. The following code snippet will do that.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;    public void drawScreen(){&lt;br /&gt;        g.setColor(255,255,255);&lt;br /&gt;        g.fillRect(0,0,getWidth(),getHeight());&lt;br /&gt;        g.drawImage(img,imgX,imgY,Graphics.TOP&amp;#124;Graphics.LEFT);&lt;br /&gt;        g.drawImage(img,imgX,imgY-getHeight(),Graphics.TOP&amp;#124;Graphics.LEFT);&lt;br /&gt;        flushGraphics();&lt;br /&gt;    }&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The effect as shown below.(The white space between the two images is just for clarity).&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_dp950kxQnQk/R8Pir3un6-I/AAAAAAAAAAc/Fn2yiNbQhMg/s1600-h/scroller_2.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://4.bp.blogspot.com/_dp950kxQnQk/R8Pir3un6-I/AAAAAAAAAAc/Fn2yiNbQhMg/s320/scroller_2.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5171226040473218018" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You can download the netbeans project source code from here. The new link &lt;br /&gt;&lt;a href="http://freewebs.com/shailesh/files/Scroller.rar"&gt;Scroller.rar&lt;/a&gt;&lt;br /&gt;The mediamax server got shut down I supoz. Thanks Nacho for pointing out&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7752976851994353052-8136352281633631396?l=agenthunts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://agenthunts.blogspot.com/feeds/8136352281633631396/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7752976851994353052&amp;postID=8136352281633631396' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/8136352281633631396'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7752976851994353052/posts/default/8136352281633631396'/><link rel='alternate' type='text/html' href='http://agenthunts.blogspot.com/2008/01/creating-scrolling-images-j2me.html' title='Creating scrolling images J2ME'/><author><name>AgentHunt</name><uri>http://www.blogger.com/profile/02347899306127799366</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_dp950kxQnQk/R5eKfv_UQRI/AAAAAAAAAAM/qNdhDVMg2cg/s72-c/track.png' height='72' width='72'/><thr:total>3</thr:total></entry></feed>
