That One Guy

Members
  • Content count

    11
  • Joined

  • Last visited

Community Reputation

100 Neutral

About That One Guy

  • Rank
    Member
  1. Microsoft Windows, SDL, and closing a Window @_@;

    As I stated, I've tried multiple things. The first I tried was 'return 0;' which didn't work, and exit() was also tried. I've tried them separately and together, as well as an atexit() thing which also did nothing. EDIT: Nevermind, I just noticed my typo (aka: (&event)==0) ) and a couple of other issues. I fixed it, lol
  2. Hi... After having to install Windows 7, I've set up Codeblocks with MinGW and SDL. Now, then, I've been trying to get some things working. I've gotten a window open (just a simple, stupid test program) and can keep it open, but it won't close unless I use Task Manager to force it shut. I've tried everything I could think of and I never had this particular problem on Linux. It closes on its own, like any other window, if I don't have a loop to keep it open, but with the loop? Complete and total failure to terminate. [CODE] #include "SDL.h" #include <stdio.h> #include <stdlib.h> #define WINDOW_WIDTH 640 #define WINDOW_HEIGHT 480 SDL_Surface *window; union SDL_Event event; int main(int argc,char *argv[]){ if(SDL_Init(SDL_INIT_VIDEO)!=0){ printf("Unable to initialise SDL: %s\n",SDL_GetError()); return 1; atexit(SDL_Quit); return 1; } SDL_WM_SetCaption("Windows SDL Test",NULL); window=SDL_SetVideoMode(WINDOW_WIDTH,WINDOW_HEIGHT,32,SDL_DOUBLEBUF); if(window==NULL){ printf("Unable to set video mode: %s\n",SDL_GetError()); return 1; } while(1){ while(SDL_WaitEvent(&event)==0){ switch(event.type){ case SDL_QUIT: SDL_Quit(); } } } } [/CODE] As with other code I've shown on this site, there are things I wouldn't want to do in a program I plan to release. I can't move onto the next bit of SDL testing on Windows until I get this issue resolved, though, and searching for hours has revealed nothing helpful. The outer loop is there because, without it, the window closes instantly.
  3. SDL text-entry issues: The Sequel

    Firstly, let me just thank you for the idea to add /usr/include/SDL to the include path! It took me a few moments to figure out I had to add it in the 'compiler' page of Code::Blocks' options and not the 'linker' one, but your choice of words helped me out there. As for user_input being included in a printf, that was only for my own testing purposes. I feel a need to stress that this source is still, sometimes, going to have my testing doodats in it and is far (very, very, very far) from being anything release-worthy. As long as I don't do those things (and I know not to), things will be fine. As for all advice, in general, it is very much appreciated and will be taken into consideration as I continue. I seriously can't thank you two enough for what I've already been given! EDIT: I nearly forgot what else I was going to ask! How might I force-uppercase input? I would prefer not to use an all-caps font, so is there a way to coax a program into treating input as though shift or capslock is in effect? @_@;
  4. SDL text-entry issues: The Sequel

    For starters, rip-off, I am indeed using C. Allow me to comment on some of your comments: 1. The preprocessor usage was only to test it. I've changed it to just hardcoded values within SDL_SetVideoMode(). 2. String.h, which I'm guessing (because it isn't an hpp) works with C, will be tested out at a later time. I'm rather unfamiliar with it, in all honesty. Things can be adapted. 3. unistd was included out of recent habit, thanks for pointing that out, lol 4. text input doesn't need to be very complicated for this game or the next two titles I've considered. Name-entry for up to 9 letters (used 'alexander' as a reference for name length possibilities, so as not to cheat people out of using favourite names) and NPC conversation input won't examine anymore than the first four letters of input (exactly the way Ultima did it, because I'm a retrojunkie for things I like). 5. SDL, in my Linux Mint Debian Edition as well as all other distros I've used, never compiles for me (gcc with codeblocks) unless I use the headers as though they're in a subdirectory. I do what works for me, and others will be welcome to change that aspect of the code if they would prefer when I release it with the game. ---------------------------------------------------------------------------------------------------------------- Before my list becomes even more ridiculously long, I'll cut it with this: I'm aware of many of the things you've pointed out, and I really should have made it clear with better commenting or something. You've supplied some helpful information, though, and what I can use will be used. @_@; Thanks for all this feedback, I'll definitely make a copy of these posts in a file for reference and will work on correcting/revising some things before I continue with my work (to make sure future work won't need to be rewritten along with what I already have). You've been an amazing help, where your advice actually helped. Admittedly, no one can string together a reply like that and have all of their suggestions be of benefit, but you've given me quite a heap to work with!
  5. SDL text-entry issues: The Sequel

    Oh, THANK you! I seriously and completely appreciate this! That's one of my problems resolved, so that's a good start for today... Now, to put this to use.
  6. SDL text-entry issues: The Sequel

    Well, now the following text is giving me an error: [code]br_panel[0]={"[S]tart new quest"};[/code] (The error being "expected expression before '{' token" which I've gotten before in this context and still dont 'get') There will be mistakes and problems, as this is a learning project as much as it is an important one to me. If someone can shed some light on this error, he or she has tripled my chances of getting this finished successfully. :3
  7. Well... This is lame. I can't quite get this input thing working properly (second time having tried input, if I still had my first source I'd only have the backspace and uppercase to worry about). Basically, text won't appear unless you hit backspace several times (didn't act like that the first time), and due to the unicode stuff, I don't have access to shift-uppercase. What I'm trying to accomplish is a backspace that works (instead of turning things into t's or other letters) and to have the user's input always be uppercase. Here's my unpleasant-to-the-eye sourcecode, please be gentle. @_@ I'm including all of what is in this file, just in case: [code]#include "/home/mdeans/Fiendlight/plyr.h" #include "SDL/SDL.h" #include "SDL/SDL_image.h" #include "SDL/SDL_mixer.h" #include "SDL/SDL_thread.h" #include "SDL/SDL_ttf.h" #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <math.h> #define WINDOW_WIDTH 640 #define WINDOW_HEIGHT 480 SDL_Surface *surface[34]; ///0 = window, 1 = frame, 2-10 = lower box's text, 11-20 = upper box's text SDL_Event event; SDL_Rect src,dest; SDL_Color font_color; TTF_Font* mt_font; char tr_panel[40]; char br_panel[20]; char user_input[9]; void plyr_talk(); void plyr_attk(); void plyr_ztat(); void plyr_get(); void plyr_look(); void plyr_warp(int how,int where[3]); int input_slot; int game_start(),game_load(),game_credits(),game_field(),game_battle(); int main(){ if(SDL_Init(SDL_INIT_VIDEO)!=0){ printf("Unable to initialise SDL: %s\n", SDL_GetError()); return 1; } else{ SDL_EnableUNICODE(SDL_ENABLE); if(TTF_Init()!=0){ printf("Unable to initialise SDL_TTF: %s\n", SDL_GetError()); return 1; } else if(TTF_Init()==0){ mt_font = TTF_OpenFont("gfx/FreeMono.ttf",16); if(mt_font==NULL){ printf("Unable to load font: %s: %s",mt_font,TTF_GetError()); } } SDL_WM_SetCaption("Fiendlight",NULL); surface[0] = SDL_SetVideoMode(WINDOW_WIDTH,WINDOW_HEIGHT,32,SDL_DOUBLEBUF); if(surface[0]==NULL){ printf("Unable to set video mode: %s\n", SDL_GetError()); return 1; } surface[1] = IMG_Load("gfx/frame.png"); SDL_Color font_color = {180,180,180}; surface[2] = TTF_RenderText_Solid(mt_font,"[S]tart new quest",font_color); surface[3] = TTF_RenderText_Solid(mt_font,"[C]ontinue your journey",font_color); surface[4] = TTF_RenderText_Solid(mt_font,"[V]iew the credits",font_color); src.x = 0; src.y = 0; src.h = surface[1]->h; src.w = surface[1]->w; dest.h = 480; dest.w = 640; dest.x = 0; dest.y = 0; SDL_FillRect(surface[0],NULL,SDL_MapRGBA(surface[0]->format,0,0,0,255)); SDL_BlitSurface(surface[1], &src, surface[0], &dest); dest.x = 410; dest.y = 280; SDL_BlitSurface(surface[2], &src, surface[0], &dest); dest.y = 296; SDL_BlitSurface(surface[3], &src, surface[0], &dest); dest.y = 312; SDL_BlitSurface(surface[4], &src, surface[0], &dest); SDL_Flip(surface[0]); //while(1){ while (SDL_WaitEvent(&event) !=0){ switch (event.type) { case SDL_QUIT: exit(0); case SDL_KEYDOWN: if(event.key.keysym.sym == SDLK_s){ game_start(); } else if(event.key.keysym.sym == SDLK_c){ ///game_load(); } else if(event.key.keysym.sym == SDLK_v){ ///game_credits(); } } } //} } } game_start(){ surface[1] = IMG_Load("gfx/frame.png"); SDL_Color font_color = {180,180,180}; surface[2] = TTF_RenderText_Solid(mt_font,"By what name shalt",font_color); surface[3] = TTF_RenderText_Solid(mt_font,"thou be known?",font_color); surface[4] = TTF_RenderText_Solid(mt_font,user_input,font_color); src.x = 0; src.y = 0; src.h = surface[1]->h; src.w = surface[1]->w; dest.h = 480; dest.w = 640; dest.x = 0; dest.y = 0; SDL_FillRect(surface[0],NULL,SDL_MapRGBA(surface[0]->format,0,0,0,255)); SDL_BlitSurface(surface[1], &src, surface[0], &dest); dest.x = 414; dest.y = 280; SDL_BlitSurface(surface[2], &src, surface[0], &dest); dest.y = 296; SDL_BlitSurface(surface[3], &src, surface[0], &dest); dest.y = 312; SDL_BlitSurface(surface[4], &src, surface[0], &dest); SDL_Flip(surface[0]); input_slot = 0; while(1){ while(SDL_WaitEvent(&event)!=0){ switch(event.type){ case SDL_QUIT: exit(0); case SDL_KEYDOWN: if(event.key.keysym.sym == SDLK_RETURN){ printf(user_input); } else if(event.key.keysym.sym != SDLK_RETURN){ if(event.key.keysym.sym != SDLK_BACKSPACE){ if(input_slot <= 8){ input_slot = input_slot + 1; } SDL_EnableUNICODE(SDL_ENABLE); user_input[input_slot] = event.key.keysym.unicode; } else if(event.key.keysym.sym == SDLK_BACKSPACE){ user_input[input_slot] = "_"; if(input_slot>=0){ input_slot = input_slot - 1; } } } surface[1] = IMG_Load("gfx/frame.png"); SDL_Color font_color = {180,180,180}; surface[2] = TTF_RenderText_Solid(mt_font,"By what name shalt",font_color); surface[3] = TTF_RenderText_Solid(mt_font,"thou be known?",font_color); surface[4] = TTF_RenderText_Solid(mt_font,user_input,font_color); src.x = 0; src.y = 0; src.h = surface[1]->h; src.w = surface[1]->w; dest.h = 480; dest.w = 640; dest.x = 0; dest.y = 0; SDL_FillRect(surface[0],NULL,SDL_MapRGBA(surface[0]->format,0,0,0,255)); SDL_BlitSurface(surface[1], &src, surface[0], &dest); dest.x = 414; dest.y = 280; SDL_BlitSurface(surface[2], &src, surface[0], &dest); dest.y = 296; SDL_BlitSurface(surface[3], &src, surface[0], &dest); dest.y = 312; SDL_BlitSurface(surface[4], &src, surface[0], &dest); SDL_Flip(surface[0]); } } } } [/code] If you see any other ways I could improve this wreck, I'll accept suggestions, but I really just want to get backspace and caps working. I hope someone can and will help. Any assistance is greatly appreciated and will be (likely) included in my credits. [EDIT: I notice that I kinda accidentally enabled unicode twice. Wasn't intentional.]
  8. SDL_TTF text entry?

    Alrighty, then, I see that SDL's innate input was more flexible than I originally thought! I'll take some time to play about with it and see if I can get something working.
  9. SDL_TTF text entry?

    Well, I was trying (unsuccessfully, obviously) to fill a generic input char array which could be used as various things like for character-naming or things said to an NPC. Basically it would have gone like this, if possible (doubt it is, now): [code]char input_thing[8]; //gets input //assigns input to first available array 'slot' //repeats until user hits 'enter' //copies input_thing into character's name or uses it to get a response from an NPC[/code] Basically, I was being stupid and making something more complicated than it needed to be for the sake of over-sorting, I think. It shouldn't be a problem after the information you've given me, though! Thanks!
  10. SDL_TTF text entry?

    It isn't the display of the input which gives me the trouble, I really should have clarified this. It is more about how the input is received. I've been using something along these lines: [code]while(SDL_WaitEvent(&event)!=0){ switch(event.type){ case SDL_KEYDOWN: if(event.key.keysym.sym == SDLK_a){ //does stuff }[/code] ...I'm pretty sure I'll have to write a single function which can take input from every necessary key, unless there's a better way (I figured SDL might have a function which sorta simulates the input capability of an unix terminal, but I'm starting to guess that was wrong). As for displaying, I've not been doing it very intelligently. There /is/ a way to use or define an entire char array at once, right? If so, I should try that instead. I'm sure there is, but I can't remember... x_x;
  11. SDL_TTF text entry?

    I'm in kind of a goofy scenario right now. Two things must be done before I can get back into working on this (Ultima-style) RPG I'm planning, and one of them is driving me loopy: How might I go about allowing the player to enter text and /blit the text entered/ like a normal SDL_TTF surface? Must I really work this entire process out from scratch? The simplest way I can invision doing it is by taking a keypress, adding it to my user_input variable, taking another and adding it to the next slot of the char array (if this is a bad idea in some way, let me know, but this isn't the question I'm asking) and continuing until the user presses 'enter' to finish. The way I'm asking about is probably impossible with plain SDL: Is it possible to simply take the input, adding it and blitting the surface with each keypress so that it enters (from the player's perspective) as simply as typing in a word processor? If not, I understand, I could go with my alternate plan (requiring a ROYALLY huge rewrite and replanning, but it is possible and I'd be willing if I had to do so). The first method I mentioned would have involved a separate if/else for each alphabetical key, and would result in tremendous tedium, but I can do that if need be, also. I'm probably horribly wrong about these methods and there might be a simpler way, so I'm asking: Could someone lend me a little advice, or a tutorial link/etc? Thanks to whomever can help! @_@; EDIT: Just to be clear about this, I'm using C.