## Recommended Posts

How do i open an image to use it as Texture2D information without D3DX11CreateShaderResourceViewFromFile? And how it works for different formats like (JPG, PNG, BMP, DDS,  etc.)?

I have an (512 x 512) image with font letters, also i have the position and texcoord of every letter. The main idea is that i want to obtain the image pixel info, use the position and texcoords to create a new texture with one letter and render it. Or am I wrong in something?

##### Share on other sites

First you would load your image into an array of bytes, representing the pixels of the image, essentially a bitmap. Then you can manipulate this array any way you like, including extracting portions of it to form a new texture. A pixel at location {x, y} would be addressed as

data[y*imageWidth + x]

To load a bitmap you could write you own parser by looking at the specs of a specific file format (BMP is fairly straightforward to load, others more challenging), or you could save yourself some time and use a library that does it for you. I prefer stb_image, it's lightweight and easy to use.

After that it's simply a matter of using DirectX API to initialize a Texture2D with your data. IIRC, you can pass a pointer to your bitmap as pSysMem member of D3D11_SUBRESOURCE_DATA, when calling ID3D11Device::CreateTexture2D.

Another option would be to actually preprocess you font into a set of textures, one per character. Again, stb_truetype by the very same Sean Barrett could do that for you.

Yet another option is to actually use a single font texture and use appropriate UV coordinates to draw a protion of your texture, containing the desired character. Personally, I would go with this option (I have tried both recently, and having a single texture just meant that much less bookkeeping, although it may well be different with your project), and since you already know the texcoords of each character in you texture, it shouldn't be too hard to implement.

Edited by dietrich
Accidentally submitted by Ctrl+Enter

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627719
• Total Posts
2978789
• ### Similar Content

• By SR D
I've been learning how to do vertex buffers plus index buffers using Ogre, but I believe this is mostly the same across several engines. I have this question about using vertex buffers + index buffers.
Using DynamicGeometryGameState (from Ogre) as an example, I noticed that when drawing the cubes, they were programmatically drawn in order within the createIndexBuffer() function like so ...

const Ogre::uint16 c_indexData[3 * 2 * 6] = { 0, 1, 2, 2, 3, 0, //Front face 6, 5, 4, 4, 7, 6, //Back face 3, 2, 6, 6, 7, 3, //Top face 5, 1, 0, 0, 4, 5, //Bottom face 4, 0, 3, 3, 7, 4, //Left face 6, 2, 1, 1, 5, 6, //Right face };
From the above, the front face is drawn using the vertices 0, 1, 2, 2, 3, 0. But when reading in thousands of vertices from a file, one obviously doesn't code an array specifying which vertices make up a face.
So how is this done when working with a large number of vertices?
• By mrpeed
I wrote Snake in Python 3 using Pygame and was wondering if anyone can do a code review of it? If this is the appropriate fourm to post such a thing?
Some things to mention:
1. I realize I could have used a dict in the place of my Segment class, but I decided to go with the class because it looked more clean to me.
2. I used recursion heavily, though I could have used a list instead. I decided to do it recursively for practice and fun (I don't use recursion often).
3. I don't have doc strings for any of my functions.
4. I probably could have used my get_all_snake_segment_locations function to avoid recursion.
5. I set fps to 10 to limit the speed of the game. Is this a bad way to do such a thing?
6. I attached an input manager I created and unit tests for my game for completeness. Though, I'm only asking the actual game to be reviewed, if you want to look at those you can. Also, note the unit tests are not complete yet for several functions I changed.
7. I really appreciate anyone who takes the time to give me feedback of any kind. This fourm has been a huge help to me and I'm grateful for everyone's  insight!
test_game.py
inputmanager.py

game.py
• By Josheir
I am working on a SFML c++ program that uses two rendering windows passed from main to the function drawmessage in a class textmessage.  I was using the second window for displaying debug information that is displayed because I could not get the appropriate information from the SFML object.
With that said, here is the part of that function that works the first time through and does not on the second usage.  I really have changed the code to try and get it working.   For example I created the two objects locally here for testing.  I am sorry about the extra commented statements they help convey the message too.
There is the same problem though, the statement :     string test =     message_holder10.getString(); is working and shows "asty" on every run.  On the first run of the program there is a display of the text correctly however on the second call there is no display of it.  (I am stepping through until the display command.)
I feel like I have exhausted my tries so I am asking for help please.
If it is the font I will just die, I really don't think it is.

sf::Text message_holder10;
sf::RenderWindow windowtype3(sf::VideoMode(700, 1000), "a");

if ((space_is_used && on_last_line) || (space_is_used && ((line_number) == (total_lines - 2))))
{

//string temp_string = message::Get_Out_Bound_String();
//int length_of_string = temp_string.length();
sf::Font Fontforscore;
if (gflag == 0)
{
gflag = 1;

{
exit(1);
}

message_holder10.setFont(Fontforscore);
message_holder10.setCharacterSize(100);
message_holder10.setFillColor(sf::Color::Red);
message_holder10.setOrigin(0, 0);
message_holder10.setPosition(0, 0);
windowtype2.close();
}
message_holder10.setString("asty");

//int y_for_space = display_y_setting + (total_lines - 2) * each_vertical_offset_is;
//int this_width = 0;

//float x = message_holder.getLocalBounds().width;

//message_holder.setPosition( ( (first_width - x )/2), y_for_space);

//windowtype2.close();

string test =     message_holder10.getString();

windowtype3.clear();
windowtype3.draw(message_holder10);
windowtype3.display();

//windowtype.display();

Wait_For_Space_Press();

/////////////////////////

Before, the :      windowtype3.display()  without the clear was drawing other text in this call, just not this one particular text message with it!

Thank you so much I am wondering what it can be,

Josheir

• I'm the co-director of LM Team, a 7-member team currently constructing a fangame based upon the Mega Man series. We've been working for about 2 years now, and both of our current programmers are busy for the next 6 months or so. Because of this, we're currently looking for a programmer (or more) to take care of gameplay and animation programming. We already have a base system in place that may optionally be built upon. This will be a hobby project to invest your free time in, not a gamedev gig.
We're currently about 67% done with the OST, 75% done with the design work, and 33% done with the graphical work. As such, the specifications of what we need should remain pretty stagnant from now on.
Here's some links of our team's work, to give you an idea of what we're currently capable of achieving:
Actual Y+1 Stuff:
- Current public playlist of music
- Old footage of the first boss of the game, since been altered slightly based on feedback
- Mockups
m9m (director, composer):

- Grand Dad Reboot - Ominous Cavern
- Lands of Onlup
- Mega Man Revolution Remix - Wily 2
MrKyurem (co-director, main designer, me):
- Boil Man - 10th place in Make a Good Mega Man Level 2 Contest
NaOH (programmer [not programmer who is currently working on the engine]):
- Programmer for Make a Good Mega Man Level 2 Contest's release game (did co-op mode and leaderboard functionality)
- 15 years of programming experience
- Castlevania 3 controls romhack
- GML code beautifier
- Beat-Em-Up engine
Alm (artist):
- Cutscene for a personal project
- Tileset for Boil Man's stage in MaGMML2
- Concept sprite
Valo (artist):
- Jungle Man tileset in Mega Man SD
- Boxart for Mega Man SD
- Wily sprite
Karakato (artist):
- Robot Masters in BCA
- Idol Woman
- Stage Select for separate project
Deathro (composer):
- Through the Eye of a Prism - 2nd place in Famicompo 2015's Original category
- Mega Man SFR - Wily 2
- Geno Force - Silent Breeze
Contact
If you're interested in joining, I'd recommend signing up to Discord, as we almost exclusively communicate through this.
Discord Tags:
MrKyurem#8741
m9m#1104
Email:
LMTeam.Y1@gmail.com
• By tonemgub
Hello,

I’m writing research paper on software rasterization algorithms and at one point I gave example of triangle rasterization algorithm.

The algorithm is really basic. If the triangle is flat top or flat bottom it’s possible to determine the minimum and the maximum x values for each scan line using the equation of line for the edges. Then for each scan line fill the pixels between minimum x and maximum x values.
If the triangle is of other kind it’s possible to split it to flat top and flat bottom triangles (finding the fourth vertex) and draw it using the previous algorithm.

I need to cite a reference for this algorithm. I saw it in some book in the ‘90s and I can’t just write it without a reference. The problem is that I can’t remember where I saw it.
I already tried to look at “Computer Graphics: Principles and Practice” but the only similar algorithm there is the polygon rasterization algorithm, which is over engineered for this kind of problem, same with "Computer Graphics: C Version".
I also tried to look at “Black Art of 3D Game Programming”, which have similar algorithm but the algorithm that I saw was in another book and slightly different.

Anyone know a book with this kind of algorithm?
Any help is appreciated.

Thanks.

• 9
• 21
• 14
• 12
• 42