generate a window for ascii game - window

Im trying to write an ascii game for an assignment. The program must be written entirely in c, no c++.
How can i get the program to open a window capable of rendering ascii art? I want to create a window of a certain size, that is capable of printing in multiple colors. A simple console window is insufficient.
Also, on a related note, can anyone show me a function that will write directly to the buffer? printf is too slow, and doesnt seem to be versatile enough for the graphics i want to produce.
Any help will be greatly appreciated.
Thanks in advance.

A simple console window is insufficient.
I disagree. A console window is perfectly fine for anything you seem to want to do. Colours, full ascii range, highlighting...
Also, on a related note, can anyone show me a function that will write directly to the buffer? printf is too slow,
How fast do you need to write? If you're forming the strings yourself and calling printf, it essentially just copies it into the buffer for you.

try ncurses
altho i dont think it works for windows at this time (v5.7)
or even AAlib

You want the Windows Console API there are functions in there to do exactly what you are asking. For example use SetConsoleDisplayMode to change the console size.

Related

How to display an image in real-time using Rust?

I am trying to write a ray tracer and want to render my image in real time in a GUI window. Basically, I have a buffer: Vec<u8> that is constantly updating. The question is how do I display it on the screen after completing each row. I was thinking about using iced or egui, but couldn't figure out how to output changing image without copying it each time. Solutions that are using other toolkits are also welcome.
egui asks for TextureId:
ui.image(my_texture_id, [640.0, 480.0]);
but doesn't say where to get it
For egui there's some example here and a note here if you want to go 3D (with an example too).
For iced there's a bunch of examples, and some of them are using image/image_viewer (e.g. pokedex).
A way to go would be to copy their code, make it compile/run, and then tweak it with your logic. If something goes wrong - you'd have more input for a more concrete SO question.
Also I don't think that there's anything wrong per se in copying the data for the purpose of buffering (see this).

OverlayContainer vs. FullscreenOverlayContainer

I had some issues in full-screen mode using OverlayContainer.
The solution is to use FullscreenOverlayContainer (which also works in full-screen mode)
The FullscreenOverlayContainer is an alternative to OverlayContainer that supports correct displaying of overlay elements in fullscreen mode.
Now, I wonder why OverlayContainer exists at all:
Are there any drawbacks in using FullscreenOverlayContainer?
In which situations would we use OverlayContainer instead of FullscreenOverlayContainer?
see comment in #19434
original reasoning was that handling full-screen mode was extra code that not everyone necessarily needed
So when you want to save some extra bytes and really don't need full-scrren you may use OverlayContainer.
My take on this is to always use FullscreenOverlayContainer.

How do I clear a screen efficiently

Whenever I try to make a game or something that requires the rapid clearing of a screen, I've used system("CLS"). I now know that that is not good to use so I tried using a for loop to print new lines rapidly. While this works it looks really weird and less clear. I've seen people try to use STRING to clear a screen but whenever I try it it never works. How can I clear my screen efficiently and cleanly.
There's no standard way to clear the screen. But in any case, actually clearing the terminal and redrawing will be far too slow and glitchy for many games.
You should use either your OS's native terminal handling functions, or a cross-platform library that abstracts them.
I'd recommend ncurses, which is the latter. It basically provides an interface akin to a double-buffered graphics API, and handles all of the actual terminal twiddling so the frame swap is as fast as possible.

Get the word under the mouse cursor in Windows

Greetings everyone,
A friend and I are discussing the possibility of a new project: A translation program that will pop up a translation whenever you hover over any word in any control, even static, non-editable ones. I know there are many browser plugins to do this sort of thing on webpages; we're thinking about how we would do it system-wide (on Windows).
Of course, the key difficulty is figuring out the word the user is hovering over. I'm aware of MSAA and Automation, but as far as I can tell, those things only allow you to get the entire contents of a control, not the specific word the mouse is over.
I stumbled upon this (proprietary) application that does pretty much exactly what we want to do: http://www.gettranslateit.com/
Somehow they are able to get the exact word the user is hovering over in almost any application (It seems to have trouble in a few apps, notably Windows Explorer). It even grabs text out of obviously custom-drawn controls, somehow. At first I thought it must be using OCR. But even when I shrink the font so far down that the text becomes a completely unreadable blob, it can still recognize words perfectly. (And yet, it doesn't recognize anything if I change the font to Wingdings. But maybe that's by design?)
Any ideas as to how it's achieving this seemingly impossible task?
EDIT: It doesn't work with Wingdings, but it does work with some other nonsense fonts, so I've confirmed it can't be OCR.
You could capture the GDI calls that output text to the display, and then figure out which word's bounding box the cursor falls in.
Well, for GDI controls you can get the position and size of the control, and you can usually get the font info. For example, with static text controls you'd use WM_GETFONT. Then once you have that you can get the position of the mouse relative to the position of the control and use one of the font functions, perhaps something like GetTextExtentPoint32 to figure out what is under the cursor. I'm pretty sure the answer lies in that direction...
You can run dumpbin /imports on the other application and see what APIs they are calling.

what language/libraries an app that has a video preview window?

I want to make a simple assistant for putting together AviSynth scripts. This would be a windows desktop application that would have a "preview" screen of an avi movie, which would give you a timeline, play, fast-forward, rewind, advance and go back frame-by-frame. The program would need to know the frame number of the current frame in the player and its filename.
What language is best suited for this? I know PHP ( I understand that this is not a contender ) and am familiar with Java. My thought is that the biggest hurdle with this project will be finding a library for the video playing features. With a cursory glance, no Java video libraries jumped out at me. My next thought would be c++ for this.
The output of this program would be an AviSynth script, a plaintext file which looks like this:
AviSource("myAvi.avi")
Crop(0, 0, 320, 240)
Blur(0.1)
There are a few tool kits that can do tihs:
C#: DirectShow (DirectX)
Java: JMF
If you have Avisynth installed, the only thing you need for preview (If I understood, that's your need) is something that can decode uncompressed video. It would open like a normal file. I'm sure there are video players implemented fairly well in Java, but I don't know how much functionallity from them you need. Anyway parsing scripts is not easy - I recommend you not to try to if you don't need to.
EDIT: I'm sorry, I thought you needed a very specific app, but from what you seem to need, you don't need to code anything, use AVSP!
Please watch this video, it shows how straightforward it is. It has advanced functions such as auto-completion, (even from your own auto-loading scripts!) syntax coloring, macros, automtic importing, drag&drop (of a video, for instance - just drag it to the video and AVSP makes the loading) scrit preview with zoom and all stuff, you can use automatic or custom sliders (you can make a slider that re-writes a number on the script in real time, for instance for hue/luminosity/contrast/etc. that would be cumbersome to control via script), checkboxes & radio buttons (for boolean values, etc...), text fields that alter strings in real time, and basically anything you need... Please check it out.
Also, VirtualDubMod is OLD.
And yep, AVSP is free, both gratis and libre! =)

Resources