My subject line doesn't explaine it very well. I want to make an offscreen surface(preferrably my own) where I have a pointer to the surface and can do all my own raster ops, then BitBlt() to my window. There are a lot of windowy things I do not understand well yet. Device context is one of them. I asked in an NG and got good response: "Look up CreateDibSection(). This will allow you to create a bitmap of a specified structure that you can set bits on in code. CreateCompatibleDC() is no good unless you are just going to access it via GDI functions." I looked up CreateDibSection() and it does provide a pointer to the start of the surface. Thats good. Iczelion's tutorial #25 is close to what I want to do, but I need to have acess to the data of my bitmap. From the tut: .if uMsg==WM_CREATE invoke LoadBitmap,hInstance,IDB_MAIN mov hBitmap,eax I dont think I want to use LoadBitmap, unless I can have access to the pixels. So I will load a bitmap into my own buffer (or Dib) .elseif uMsg==WM_PAINT invoke BeginPaint,hWnd,addr ps mov hdc,eax invoke CreateCompatibleDC,hdc mov hMemDC,eax invoke SelectObject,hMemDC,hBitmap This section is what I'm not sure about. CreateCompatibleDC creates a DC compatible with my main window? Then SelectObject assigns the bit map to the created DC. I know, I just stated the obvious. So I know SelectObject works with bitmaps loaded with LoadBitmap, does it work with Dibs? Sorry if this is not exactly an assembly language related post. Try posting assembly language in a Windows NG and the thread will just turn into "why dont you use C++, it's much easier" invoke GetClientRect,hWnd,addr rect invoke BitBlt,hdc,0,0,rect.right,rect.bottom,hMemDC,0,0,SRCCOPY invoke DeleteDC,hMemDC invoke EndPaint,hWnd,addr ps
asm_happy, That's OK, it's a WINDOWS assembly forum, so we don't mind windows stuff if you don't mind we answer is asm code ;-) What I don't see in your post is WHY you are playing with the bitmaps? Are you trying to create a bitmap 'on the fly' and then blit the whole thing to the screen (btw, this is a good method to avoid screen flashing)? How much of the bitmap are you writing? Is it possible to have a few "stock" images on hand, and just paste small bitmaps to a general background to make the full display? BTW, 'bitmap" and 'DIB' mean the same thing these days. 'DIB' stands for 'Device Independent Bitmap,' a hangover name from the bad old days of windows 1.0 when a bitmap did not contain color information (thus took the pallet of the device, and was device dependent). Yep, GDI stuff is confusing at first. Think of the device context as an artist's workshop, with pens and brushes and other toys there to draw WITH, and the selected bitmap as the canvas (or surface) to draw ON. GDI usage rules are pretty simple: if you borrow something, put it back. If you create something, destroy it when done. Let us know more of what you're trying to accomplish, and don't forget the GAMES forum here, those guys tend to be smart about GDI drawing (when they aren't using exotic technologies like DirectX). -------------------------------- "I think Smithers picked me because of my motivational skills. Everyone says they have to work a lot harder when I'm around."
hey asm_happy, i'm not sure if i've already done what you're looking for but you could have a look at some of my sources that use "backbuffering" on my website. it creates an invisible "screen" BitBlts everything on it, and when everything is finished it copies the invisible "screen" to the main window. that avoids screen flashing. what is really worth to download is -worm. it's a game that uses that method. bye
Here a better explanation of what I want to do: I want to make a roguelike game. Graphical roguelikes use tiles to make make the final display. Looking at the GDI stuff, I thought, "How am I easily going to use just part of a bit map and place on the screen?" The best idea is to put my tiles on one bitmap. If my tile are all 16x16 pixels and lines up like a grid, I can copy the tile I need from my tile source to my logical screen. To do that how ever, I need a pointer to GDI created surface. BitBlt requires a source and dest hdc. I wish source could just be a pointer to the start of a buffer, but no. So I want an accesible offscreen surface the same size as my window to filp to the primary window when I want to update. I tried to use CreateDIBSection last night, but a lot of dependencies. Also I realized how rusty I've become at assembler. Haven't done any serious coding for years. Fortunatly I remembered something I downloaded: TinyPtc http://www.gaffer.org/tinyptc/ It's a SMALL c library that will give you a window in GDI or DirectX. Does color space conversion. Thats it. It was made for 64k intros, so no extra fluff code. Very clean code, so it should be easier to translate to assembly. After looking closely at the code I realized it gives me exactly what I want. An array of ints the size of the window as a backbuffer. Just use a pointer to copy data to the backbuffer. I also posted here looking for windowed DirectX code, now I have some good code. For now, I think I will spend a little time writeing to the backbuffer just to get my assembly legs again. BTW I'm using MASM, is there a place to get information on MASM keywords etc?? Thanks
asm_happy, To pick up as much info around as you can, have a look at the MASM32v6 package as it has some reasonable help files that cover most of the useful masm keywords. Other stuff too, lots of examples etc.. It may not be what you are after if you have your own system going to write asm but it has a lot of useful stuff for assembler language programmers. http://www.pbq.com.au/home/hutch/masm.htm Regards, email@example.com
OK, main display, backbuffer, single bitmap holding your tiles. Cool, we got a framework. You will need TWO memory device contexts (a memory dc doesn't belong to a window). Get those with CreateCompatableDC, compatable with the window's DC, of cource. I'm going to call this main window's DC 'DC1'. CreateCompatableDC the first DC (let's call it DC2) for the backbuffer. You need a bitmap on it the size of your display window. CreateCompatibleBitmap will make you one sized as you need. Keep in mind this is an UNINITIALIZED bitmap, meaning it has random bits on it. Random is OK is you intend to completely tile over it. So that's the next step. CreateCompatableDC the 2nd DC (DC3), and use LoadBitmap (or such) to get your resource bitmap of the individual tiles. You seen to have the idea how to pull tile 'X' out of this visual array. The simplest way is to make the tiles all in the same direction, so the top, height, and width is always the same, just index in (X pixels per side) * (image index) pixels left to get the correct tile. So, your paint routine creates these two dc's, gets the bitmaps on them, uses DC3 as the source to blit tiles onto DC2. Once DC2 is completely tiled over, blit the entire DC2 to DC1. That's basically it, except for cleanup. SelectObject back the orgional bitmaps inth DC2 and DC3, then DestroyObject the 2 bitmaps (1 created, 1 from resource), then DestroyDC the two created DC's. Let us know how you do. :-) ---------------------- "Iíve figured out an alternative to giving up my beer. Basically, we become a family of travelling acrobats."