Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

126 Neutral

About lmsmi1

  • Rank
  1. So I've got this program to run successfully, but am getting a problem: when I hit the return key, it prints a musical note onto the screen. It does do what I want it to do: make a new line, but it prints the musical note at the beginning of the buffer. How do I get rid of this? Where do I place buf.clear() to get the note character to go away? Here's the full code:   #include <SFML/Graphics.hpp> #include <SFML/System.hpp> #include <SFML/Window.hpp> #include <vector> int main() {     /* Set Variables */     sf::Color bgColor;     sf::Font mainFont;     sf::String pre = "System!>";     sf::Text prefix;     sf::String buf;     sf::Text buffer;     sf::String lastStr;     sf::Text lastLine;     std::vector<sf::String> lineVector;     int lineCounter = 1;     int currentVectorPosition = 0;     int currentPrefixY = 0;     int i = 0;     int x = 0;     bgColor.r = 0;     bgColor.g = 0;     bgColor.b = 203;     sf::RenderWindow rWnd(sf::VideoMode(800, 600), "SFML Window");     rWnd.setSize(sf::Vector2u(800, 600));     mainFont.loadFromFile("dos.ttf");     prefix.setCharacterSize(18);     prefix.setColor(sf::Color(255, 255, 255));     prefix.setString(pre);     prefix.setFont(mainFont);     prefix.setPosition(0, currentPrefixY);     prefix.setStyle(sf::Text::Regular);     buffer.setCharacterSize(18);     buffer.setColor(sf::Color(255, 255, 255));     buffer.setFont(mainFont);     buffer.setPosition(prefix.getPosition().x + prefix.getGlobalBounds().width + 1, 0);     buffer.setString(buf);     buffer.setStyle(sf::Text::Regular);     lastLine.setCharacterSize(18);     lastLine.setColor(sf::Color(255, 255, 255));     lastLine.setFont(mainFont);     lastLine.setPosition(0, 0);     lastLine.setString(lastStr);     lastLine.setStyle(sf::Text::Regular);     while(rWnd.isOpen()) {         rWnd.clear(bgColor);         sf::Event event;         while(rWnd.pollEvent(event)) {             if(event.type == sf::Event::Closed) {                 rWnd.close();             }             if(event.type == sf::Event::KeyPressed) {                 if(event.key.code == sf::Keyboard::Escape) {                     rWnd.close();                 }                 if(event.key.code == sf::Keyboard::Return) {                     lineVector.push_back(buf);                     buf.clear();                     lineCounter += 1;                 }             }             if(event.type == sf::Event::TextEntered) {                 if(event.text.unicode == '\b') {                     if(!buf.isEmpty()) {                         buf.erase(buf.getSize() - 1, 1);                     }                 } else {                     buf.insert(buf.getSize(), event.text.unicode);                 }             }         }         /* Somewhere between here */         if(lineCounter == 1) {             prefix.setPosition(0, 0);             buffer.setPosition(prefix.getPosition().x + prefix.getGlobalBounds().width + 1, 0);         } else {             x = 0;             i = 1;             currentVectorPosition = 0;             currentPrefixY = 0;             while(i < lineCounter) {                 prefix.setPosition(0, currentPrefixY);                 lastLine.setPosition(prefix.getGlobalBounds().width + 1, prefix.getPosition().y);                 x++;                 lastLine.setString(lineVector[currentVectorPosition]);                 rWnd.draw(prefix);                 rWnd.draw(lastLine);                 currentPrefixY = prefix.getPosition().y + prefix.getGlobalBounds().height;                 i += 1;                 currentVectorPosition += 1;             }             prefix.setPosition(0, currentPrefixY);             buffer.setPosition(prefix.getPosition().x + prefix.getGlobalBounds().width + 1, prefix.getPosition().y/* + prefix.getGlobalBounds().height*/);         }         buffer.setString(buf);         rWnd.draw(prefix);         rWnd.draw(buffer);         rWnd.display();     } }
  2. I've got a few questions about using SDL_ttf to render text:   1. How can I render the text to a buffer or array? 2. How do I get the length of a single character rendered from a TTF document? 3. If it's possible to do 1 and 2, then how exactly do I render a new line ('\n')?   Here's some code I need to modify. Feel free to modify it and post what you can here. #include "include/SDL/SDL.h" #include "include/SDL/SDL_ttf.h" int currentX = 0; int currentY = 0; SDL_Surface* screen; SDL_Surface* fontSurface; SDL_Color fColor; SDL_Rect fontRect; SDL_Event event; TTF_Font* font; //Initialize the font, set to white void fontInit(){ TTF_Init(); font = TTF_OpenFont("dos.ttf", 12); fColor.r = 0; // 255 fColor.g = 204; // 255 fColor.b = 0; //255 } //Print the designated string at the specified coordinates void printF(char *c, int x, int y){ fontSurface = TTF_RenderText_Solid(font, c, fColor); fontRect.x = x; fontRect.y = y; SDL_BlitSurface(fontSurface, NULL, screen, &fontRect); SDL_Flip(screen); } int main(int argc, char** argv) { // Initialize the SDL library with the Video subsystem SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE); //Create the screen screen = SDL_SetVideoMode(320, 480, 0, SDL_SWSURFACE); //Initialize fonts fontInit(); //Print to center of screen // printF("Hello World", screen->w/2 - 11*3, screen->h/2); printF("Hello world!", currentX, currentY); do { // Process the events while (SDL_PollEvent(&Event)) { switch (Event.type) { case SDL_KEYDOWN: switch (Event.key.keysym.sym) { // Escape forces us to quit the app case SDLK_ESCAPE: event.type = SDL_QUIT; break; default: break; } break; default: break; } } SDL_Delay(10); } while (Event.type != SDL_QUIT); // Cleanup SDL_Quit(); return 0; } Thanks in advance.   ~lmsmi1
  3. @zacaj   The problem is getting individual characters from the TTF and assigning them each to a keystroke.
  4. How am I supposed to get a BMP of every character? And by array you mean a BITMAP array?     Oh look what I found on Google:   http://www.dafont.com/perfect-dos-vga-437.font     How am I supposed to use a TTF in SDL? (I know about SDL_ttf() and such.) I'm assuming I make a black BG that takes up the whole screen, then assign a letter in the TTF to each keystroke? That should work, correct?
  5. How am I supposed to get a BMP of every character? And by array you mean a BITMAP array?
  6. Apparently standard C++ doesn't offer fullscreen consoles in Win7, so I've come to OpenGL with high hopes. I figure there's some way to make a virtual console in C++ with OpenGL somehow, so let's get to what I want to make:   1. I don't want to make an OS, I just want a fullscreen (no window or borders, just a black BG with text on it) application. 2. I want it to look like DOS (refer to 1). 3. I don't want to make a CLI, I want to make a small console program that takes up the whole screen.   Does anyone know how to achieve my goal? Do I even need to use OpenGL?
  7. Ah gfxgangsta! That's why! Okay, my weapons definition file has an XML structure. Is that the best for importing strings & values into the game, or should I use JSON or something else?
  8. Hallo again everyone. As you may know, I'm developing an FPS in C++ with GLUT. I've got GLUT setup with Code::Blocks 12.11, and need some help with some things:   1.) Reading & Displaying an OBJ file 2.) Applying a texture to the OBJ in the window   So I've got no experience with OpenGL except using/modifying the sample code given by Code::Blocks. Does anyone know how to load an OBJ and then apply a texture?
  9. Uhm, I've come upon a little problem. I've switched to a main weapon XML data file, and am trying to define reload, firing, and switch animations. I don't know how to organize this in an XML file for the FPS game. Can anyone help me with this problem?
  10. Well, thanks for your replies. I already have OBJs for weapons and such, plus sounds, and definition files for the game. I've got GLUT set up, but I guess I have no luck according to you all :(. I'll plan more and watch mor TUTs, and I'll come up with a way to organize it all.   Thanks guys :).
  11. Well, hi there :). I was directed here by another person on a website, and am confident that GD's community will help me tremendously.   I am currently starting a very big project called "R3C0N". It is an FPS gme plan that's game engine will be coded in C++. I know a moderate level of C++, including the usual i/o with consoles, and  little Win32 API, however I have absolutely no knowledge of libs such as GDK+, OpenGL, DirectX, etc. When I came up with the idea of an FPS game coded in C++, I planned it out very roughly, then smoothed it out as I researched what was possible with C++. Here is the beta plan:   Game Engine - Reads the files neccessary to play the game, displays graphics, etc. Game Folders - Contain the neccessary files (.wepn, .wav, .obj, .texture, etc.)   I have a complete plan if you would like me to post it, but since this is my first post here, I thought I would just ask the bare minimum, as I don't know what the community is like.   My main question is: what library is good for FPS games in C++? I'm using MinGW with Code::Blocks, so anything that's compatible with MinGW works for me. I am planning on having the player to be able to scope zoom, sight zoom, you know things like Call of Duty Modern Warfare 3 players can do.   Thanks in advance for any help at all. I look forward to meeting the community.   ~lmsmi1
  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!