what is the fastest way to draw pixel in win32 - c++

I'm writting a simple software renderer,
load 3d model, process vertex, rasterization, texture, lighting,
all that things, all done.
I used SDL(not using OpenGL mode) to draw pixel on its SDL_Surface,
and call SDL_Flip, so one frame appears.
for some reason now I don't want to use SDL,
I just need a double-buffer to draw pixel.
I know there're someway to do this,
OpenGL, Direct3D, gdi,
maybe they're too "advanced" for this project,
what is the direct(or fastest) way to draw pixels to back-buffer on win32 ?

I'd recommend using a graphics API for this (OpenGL or Direct3D), but GDI would be the easiest option. You can create a DIB (Device Independent Bitmap) using the CreateDIBSection function which returns a pointer to the bitmap's memory. You can then modify the pixels of the bitmap however you please and draw it to your window's client area. See chapter 15 of Programming Windows (5th) by Charles Petzold for source code and explanation of this technique.

Related

DirectX texture and per-pixel desktop transparency

I have a directX11 texture which is of ARGB format. (different pixels has different alpha value, like the one below)
I need to render that texture on a transparent Window which means the desktop should appear behind the texture.
I am using SetLayeredWindowAttributes which could make the window transparent but it's boolean, i.e. a pixel appears either fully transparent or doesn't appear. I need to achieve per-pixel transparency level - where darkness is defined by the alpha value of the pixel (Something like AlphaBlend). How to achieve it?
Use UpdateLayeredWindow instead. Select a 32-bit ARGB bitmap into the source HDC.
A more fancy solution is WS_EX_NOREDIRECTIONBITMAP and ICompositorDesktopInterop but this is probably overkill in this case unless you need to do updates often. MSDN magazine did have a few articles about this. DirectComposition is intended to interop with Direct2D etc. where as UpdateLayeredWindow is much older and predates the DWM and any kind of visual tree rendering.

directx 9 draw font on texture

What im currently doing is drawing multiple textures on a single IDirect3DTexture9 and then scale it to make a nice animation using ID3DXSprite.
Im searching a way to draw text on that final IDirect3DTexture9, however ID3DXFont does not apparently support it.
TextOut requires the DC of the texture and in consequence requires the texture to be in format D3DFMT_X8R8G8B8, which will make me lose my opacity support.
Is there anyway to do this without coding my own font engine?
DirectX9 and C++
Thanks.

On OpenGL, is there any way to tell glTexSubImage2d not to overwrite transparent pixels?

On OpenGL, I'm using glTexSubImage2d to overwrite specific parts of a 2D texture with rectangular sprites. Those sprites have, though, some transparent pixels (0x00000000) that I want to be ignored - that is, I don't want those pixels to overwrite whatever is on their positions on the target texture. Is there any way to tell OpenGL not to overwrite those pixels?
This must be compatible with OpenGL versions as low as possible.
No, the glTexSubImage2d will copy the data to the texture directly no matter what the source or the target is.
I can only suggest you to create another texture with the data you are trying to push using glTexSubImage2d and then draw this texture to your target texture. This will lead to a pretty standard drawing pipeline so you can do whatever you want using blend functions or shaders.

SDL and Dynamic Super Resolution?

Is there a way to do DSR with SDL and OpenGL? As far as I know this is an NVidia thing (I have an NVidia card), so would this be something done in a shader? I can't find anything in the SDL reference and some googling around doesn't reveal anything either.
On the top of my head, the best way to do that would be using framebuffers.
You do your rendering on a larger FBO (FBO Documentation) than your screen resolution, then you downsample your FBO to another framebuffer that fit the size of the screen using a pixel shader.
This is OpenGL-specific, so you should be able to do it on SDL.
The OpenGL wiki has some snippet of code to render to FBO, it should be useful to get you started. And since what you wanna do is basicly downsampling, you might be interested in this thread.

How to draw texts on a 3D objects (such as sphere)

I learn OpenGL under Linux platform. Recently, I try to use texts created by glutBitmapCharacter() as the texture of some quadrics objects provided by glu or glut. However, glutBitmapCharacter() does not return a pointer so that I can't feed it to the glTexImage2D(). I had google it for quite a while, but all I found is some topic related to Android SDK which I have no experience to it.
All I can think of is to render texts and read it form buffer using glReadPixels(), then save it to a file. Next, read the pixels back from the file and refer it to a pointer. Finally, draw 3D objects with these texts as the texture (i.e. feed the pointer to the glTexImage2D()).
However, it's kind of silly. What I want to ask is: Are there some other alternative way to this?
Applying text on top of a 3D surface is not trivial with pure OpenGL. GLUT does not provide any tools for that. One possible option would be for you to implement your own text rendering methods, possibly loading glyphs using Freetype then create a texture with the glyphs and apply that texture to the polygons. Freetype-GL is a tiny helper library that would facilitate a lot if you were to do that.
Another option would be to again load the text glyphs into a texture and then apply them as decals over the geometry. That way you could still simulate a 2D text drawing in a flat surface (the decal) and then apply that on top of a 3D object.