Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

122 Neutral

About jimiwa

  • Rank
  1. Okay, sorry, but I really don't want someone to completely rewrite the program and present it (please don't take offense, however I appreciate that you answered), I was more looking for a *slight* adjustment to my code, so it would still be understandable to me and still resemble my code, but so it will work, too. I'm reposting an update, but please if you reply just make the minimum adjustment to the code to make it function correctly, because some of this code that was posted as a reply is just a touch above my level of understanding. In fact, if someone could just tell me what is going wrong with the following code, that's what I'm looking for. Now, I'm getting strange results and scrambled colors which do not represent either of the original pictures - I just want minor adjustments to my code, just enough to make it work without rewriting it. I understand that my coding style isn't that great, but I need to understand the code, and if it's altered too much from what I originally wrote, I may not understand it, as in the previous posts.. Why isn't the following code of mine working? /* program to input two .raw image files and output a .raw image file containing an average of the two pictures. */ #include <iostream> #include <fstream> #include <vector> using namespace std; // strings for file names char InputFile1[30]; char InputFile2[30]; char OutputFile[30]; // input and output streams ifstream InStream1, InStream2; ofstream OutStream; // total number of pixels in image int totalpixels; class images { public: // vectors to contain images vector<unsigned char> Pixels1; vector<unsigned char> Pixels2; // constructor images (); // load images void Load(); // average pictures and output void Merge(); private: // number of pixels in images int NumberPixels1, NumberPixels2; }; images::images(void) { // set number of pixels to 0 NumberPixels1 = 0; NumberPixels2 = 0; } void images::Load() { // set size of vectors Pixels1.resize(totalpixels * 3); Pixels2.resize(totalpixels * 3); // integers for looping int n = Pixels1.size(); int n2 = Pixels2.size(); // open input file InStream1.open(InputFile1,ios::binary); for (int i = 0; i < n; i ++) { // input next pixel color value InStream1 >> Pixels1; } // close input file InStream1.close(); // open input file InStream2.open(InputFile2,ios::binary); for (int i = 0; i < n2; i ++) { // input next pixel color value InStream2 >> Pixels2; } // close input file InStream2.close(); } void images::Merge() { // number for loop int num; // integer to hold for calculating color int colorvalue; // calculated color to be put in output file unsigned char colorchar; // number of bytes (unsigned characters) in pictures int n = Pixels1.size(); // open file in binary mode OutStream.open(OutputFile,ios::binary); // loop for entire image for (num = 0; num < n; num ++) { // set integer colorvalue to average of two R,G, or B values colorvalue = (static_cast<int>(Pixels1[num]) + static_cast<int>(Pixels2[num])) / 2; // set colorchar to character equivalent of colorvalue colorchar = static_cast<unsigned char>(colorvalue); // output R,G, or B value to file OutStream << colorchar; } // close file OutStream.close(); } int main() { // create InFile, with two images to read // OutFile, one image to create images InFile, OutFile; // horizontal (width) and vertical (height) integers int hor, ver; // input width , height cout << "Enter horizontal pixels: "; cin >> hor; cout << endl; cout << "Enter vertical pixels: "; cin >> ver; cout << endl; // calculate total pixels totalpixels = hor * ver; // input file names cout << "Enter filename 1: "; cin >> InputFile1; cout << endl; cout << "Enter filename 2: "; cin >> InputFile2; cout << endl; cout << "Enter output filename: "; cin >> OutputFile; cout << endl; // load files InFile.Load(); // manipulate and create output file of merged images InFile.Merge(); return 0; }
  2. This isn't a game, but I figured it would be okay to post on the general programming section here as I usually get sufficient answers. If anyone can answer this, I'd greatly appreciate it. Programming a program that reads two images in .raw format and merges them . Right now, I'm getting an all-black output image. Not a huge amount of code, so I'm hoping someone can help. Please forgive my unprofessional style, although I will take suggestions on style , right now I am mainly concerned about functionality. In other words, if you comment on style, please also point out what's making the program malfunction. #include <iostream> #include <fstream> /* program to input 2 image files in .raw format and average the pixels into an output file in .raw format, basically combines two images .raw files are store byte by byte red, green, and blue in the following manner: r g b r g b r g b r g b r g b .. etc.. */ using namespace std; /* Arrays to hold Red, Green, and Blue values for each entire image Picture1 comes from file 1, Picture2 comes from file 2, Picture3 will be output file */ char Picture1[7500000][3]; char Picture2[7500000][3]; char Picture3[7500000][3]; // input and output streams for file i/o ifstream inputfile1; ifstream inputfile2; ofstream outputfile; // file names char filename1[30]; char filename2[30]; char filename3[30]; // counts how many pixels in the files, files should be same length int count; void GetPictures() { inputfile1.open(filename1); count = 0; while (!inputfile1.eof()) { // input red, green, and blue values for first picture inputfile1 >> Picture1[count][0]; inputfile1 >> Picture1[count][1]; inputfile1 >> Picture1[count][2]; count += 1; } inputfile1.close(); inputfile2.open(filename2); count = 0; while (!inputfile2.eof()) { // input red, green, and blue values for second picture inputfile2 >> Picture2[count][0]; inputfile2 >> Picture2[count][1]; inputfile2 >> Picture2[count][2]; count += 1; } inputfile2.close(); } void MergePictures() { int thiscount; // integers to calculate image manipulation int p10, p11, p12, p20, p21, p22 ; // final red green blue values char c0, c1, c2; outputfile.open(filename3); for (thiscount = 0; thiscount < count; thiscount ++) { // get red green and blue values for picture 1 p10 = static_cast<int>(Picture1[thiscount][0]); p11 = static_cast<int>(Picture1[thiscount][1]); p12 = static_cast<int>(Picture1[thiscount][2]); // get red green and blue values for picture 2 p20 = static_cast<int>(Picture2[thiscount][0]); p21 = static_cast<int>(Picture2[thiscount][1]); p22 = static_cast<int>(Picture2[thiscount][2]); // add red green and blue values and divide by 2 (average rgb value) c0 = static_cast<char>((p10 + p20) / 2); c1 = static_cast<char>((p11 + p21) / 2); c2 = static_cast<char>((p12 + p22) / 2); // write red green and blue values to output file outputfile << c0; outputfile << c1; outputfile << c2; } outputfile.close(); } void main() { // ask user to input file names cout << "Filename 1: "; cin >> filename1; cout << "Filename 2: "; cin >> filename2; cout << "Output filename: "; cin >> filename3; // load pictures GetPictures(); // merge the two pictures MergePictures(); }
  3. I'm wondering how to load x files from models that I create in Blender, Blender only exports text x files. I tried an example loading an x file and displaying it, and the x file was a binary x file, it worked. But when I used the text x files I got from blender, I got an error in loading. If anyone can tell me how to load the text format x files, please tell me. (using VC++ .net 2005 and dx9) // globals: IDirect3DDevice9* Device = 0; ID3DXMesh* Mesh = 0; // within a function: ID3DXBuffer* adjBuffer = 0; ID3DXBuffer* mtrlBuffer = 0; DWORD numMtrls = 0; hr = D3DXLoadMeshFromX( "file.x", D3DXMESH_MANAGED, Device, &adjBuffer, &mtrlBuffer, 0, &numMtrls, &Mesh); if(FAILED(hr)) { ::MessageBox(0, "Mesh Loading Failed", 0, 0); return false; }
  4. I got a program to load x files from the book Introduction to 3D Game Programming with DirectX 9.0 by Frank D. Luna the program compiles with the given file which seems to be in some type of binary format, the beginning of the file looks like: --------------------------------- xof 0303bin 0032 VertexDuplicationIndices ..and a bunch of binary junk --------------------------------- files that I'm exporting from blender look more like: --------------------------------- xof 0302txt 0064 Header{ 1;0;1; } Material Material { 0.756191134453; 0.756191134453; 0.756191134453;1.0;; 0.5; 1.0; 1.0; 1.0;; 0.0; 0.0; 0.0;; TextureFilename { none ;} } -------------------------------- substituting the blender x files for the given binary x file does not work. I am using D3DXLoadMeshFromX and it is failing on me.
  5. I have visual c++ .net 2003 and I'm wondering how I can write programs to read from and write to files that can be selected at runtime. It seems to me that traditional c++ file i/o is insufficient because it requires a constant string for the filename. I don't really want to do MFC applications - I'd like to do directx applications if possible, but would also wonder how to do this in console c++. Any help would really be appreciated.
  6. I don't know why, but I guess I just haven't bothered to learn C# yet
  7. What do users of my visual c++ .net 2003 programs need to run my programs? I seem to remember something about managed programs needing the .net Framework and unmanaged c++ programs just need a few files. I write mostly unmanaged but I do use managed programming, I think, for my random functions, so most of my games would be managed because of that - I think, but I don't want users to need the Framework to run my games. Can someone help me here?
  8. I just installed the april 2005 sdk of directx and I used a previous one before, there's a difference in the lib directory - it has two directories inside of it - x86 and x64 - I need to know which of these directories to use
  9. jimiwa

    xfiles, blender, directx

    so basically I'm wondering if I exported my x file right. I chose from the menu export->directx and typed in a file name and I got an x file. The only thing is I have no knowledge of python scripts and I have no idea how to use one. If I choose export->directx from the menu and type in the file name is that sufficient to create the x file or do I actually have to learn something about python scripts? The Blender 2.3 guide that I have has very little information in it on python scripts. I don't know which script I'm supposed to use to export an x file or even what that script is, so I might need a little help, unless what I already did, simply choosing from the menu and typing in the file name (it did create an x file for me), is sufficient to create an x file usable by directx.
  10. I tried using some source code from direct3d programming books and replacing the x file with that code with my own x file that I made with blender, using visual c++ .net but have only had failure trying this. Is the problem that I have to alter the code for the specific x file, or is there something wrong with my x file? The code I used compiled and worked with the x files it came with. I'm just starting at direct3d, so forgive my lack of knowledge on this.
  11. jimiwa

    xfiles, blender, directx

    I'm not quite sure what a python script is, all I think I know is that python is a programming language.
  12. Does directx9 support wide screen display (1280*768) or is a stretched 1024*768 screen the only possibility?
  13. I am thinking of learning blender and direct3d, however, the only problem I have with blender is I may not be allowed to sell games made with it. What is a good 3d modeling software that I could use to make models for games that I can sell? I'm looking for something affordable, maya is too expensive for me.
  14. jimiwa

    blender, direct3d, xfiles

    I just got the blender 2.3 guide in paperback and I looked in the index and found nothing on xfiles. I'm wondering what kind of format I'm suppossed to save my models as and how they can be used by direct3d. Can blender do xfiles? If not, how does direct3d use blender models? Also, I'm just wondering and haven't gotten into it yet, but how is an animated model used in direct3d - is there such thing as an animated xfile or something?
  15. I'm new to blender and direct3d and want to try to learn them. I now have in my possession the official Blender 2.3 Guide in paperback. However, I looked in the index and found nothing on saving xfiles which I assumed was the typical 3d file type used in directx. I'm just wondering how I'm going to use my 3d models from blender in directx. Can blender do xfiles or will I have to use something else? Also, I'm just wondering if there are such things as animated xfiles as I don't know much about 3d programming yet. Basically I'm just wondering what kinds of files I can create with blender that can be used with directx. I know animated 3d models will be later on once I get the knowledge but I'm just wondering now how blender models in directx handle animation if someone could please tell me. BTW, I'm using Visual c++ .net 2003 Thanks.
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!