Is it possible to create a Rectangle and somehow turn it into a Texture in SDL2 C?
You can easily load images to textures using the image library but making a simple rectangle seems a lot more complicated.
It is generally not meaningful to create a texture in which all pixels are the same color, as that would be a waste of video memory.
If you want to render a single rectangle in a single color without an outline, it would be more efficient to do this directly using the function SDL_RenderFillRect.
If you really want to create a texture for a single rectangle in a single color without an outline, then you can create an SDL_Surface with SDL_CreateRGBSurface, then use SDL_FillRect on that SDL_Surface to set the color, and then use SDL_CreateTextureFromSurface to create a SDL_Texture from that SDL_Surface.
Related
I'm new to pixel shaders, and I'm trying to apply an underwater-effect to my 3d scene. I can apply it to an image and animate it easily enough, but not to my ViewPort3D. The computer just hangs when calling BeginAnimation on the effect being applied to the Viewport3D. Is this something that cannot be done in WPF?
After a little digging I learned that pixel shaders are only applied to 2 dimensional types, like images. So what I would need is called a vertex shader, which for WPF, there are none.
I want to add characters (x/y/z.., not even strings) to a window using OpenGL, WITHOUT using GLUT. I know about glutBitmapString(), but I want to avoid glut. Any suggestions...?
Last time I did this for a retro-style game, I created a bitmap font and wrote a small routine that would draw a quad with the specific character as a texture on it. Another option is to draw every pixel of the bitmap font in a seperate quad.
You can find example code here:
http://svn.berlios.de/wsvn/pong2/trunk/src/Interface.h
http://svn.berlios.de/wsvn/pong2/trunk/src/Interface.cpp
More specifically:
void Interface::createFont() initiates a bitmap font as a display list for each character
void Interface::drawText(const std::string& text) lets OpenGL call the display lists according to the string's characters
In this specific example, I wanted textured "pixels" within the characters, so each bitmap entry results in its own quad with a stock texture on it. Display lists are nowadays less favored as newer OpenGL features like FBOs and VBOs replace their functionality. I don't know if at some point display lists got deprecated as well.
The text in createFont() was created by The Gimp (http://www.gimp.org) export functionality.
Screenshot to celebrate the 20k:
I would suggest using a glyph map, which basically boils down to a bitmap texture with a bunch of letters distributed over it. Load in the texture and draw quads with texture coordinates mapped to the location of the glyph you want in the texture.
There are some drawbacks in a naive implementation that can be partially alleviated. For example, rather than drawing a ton of quads in separate draw calls, you could take a cue from Java and make immutable strings that tie to a GPU buffer and pack all the vertices and uvs you need to draw the word into that buffer. (They don't have to be immutable, just know that if you need to make a word longer or shorter, you'll have to reallocate the buffer or leave extra space to put the new letters).
The site that I used whenever I was trying to learn how to do this can be found here:
Bitmap Fonts
I have used this method with a WebGL implementation and it has worked quite well. I even have wrote a tool to generate the texture from a <canvas> element on the fly.
I have an image, I want to get a pixel color, replace a pixel color with another, and other operations on pixels.
Is there a way to do that? And what libraries are needed?
Have a look at the WriteableBitmapEx library. This will allow you to manipulate pixels directly.
I would like to display textures in different colors pretty much having this texture.
How do I do this in Silverlight?
Thanks!
alt text http://a.imageshack.us/img535/5255/leathertexture.png
Turn your texture into alpha textue. Exact steps will depend on your image manipulation software. After that simply place your texture on top of colored rectangle.
You could make pixel shader for even better result, but that would be an overkill in your case.
In WPF, I want to use a pixel shader to modify a composite image i.e. a new image overlaid on top of a previously shaded image. The new image comes in as a largely transparent image except where there is data (think mathematical functions - sine wave, etc). Anyway this process needs to repeat pretty rapidly - compose the currently shaded texture with a new image and then shade the composite image. The problem is that I don't know how to access the previously shaded texture from within my shader.
Basically, you need to add a Texture2D variable in your shader, then set that parameter as the texture you need to access before drawing the new one (i'm unsure of that process in WPF). You do something like this:
//blahblahblah variables here
Texture2D PreviousTexture;
Sampler PreviousTextureSampler = Sampler2D { Texture = PreviousTexture; };
//blahblahblah code here
then you can sample the texture with a tex2D call.