Question:
draw a red pixel in c++ without using libraries (including directx)?
xxxx1101xxxx
2009-06-16 12:07:31 UTC
How in the hell would you go about drawing a single red pixel from c++ (os is windows vista). I dont want to use directx, opengl, ogre, or any other graphics library and i dont want to hear about how god damn hard it is. I just want to ******* see how its done.
Three answers:
Found my brain but lost my mind
2009-06-19 04:38:04 UTC
wow! for someone asking for free help, you're awfully belligerent in how you ask it. On sheer faith in humanity, I'll answer your question anyway.



in explaining how its done (assuming that you're planning to actually do something with the info) you have to understand how the operating systems works.



To actually set the red pixel itself is rather simple. Here's a function to start you out:



int setPixelRed()

{

__asm

{

MOV EAX, ..

INT 10

}

}



The "EAX" register holds the parameter(s) & function (including position & color) desired for the interrupt. The "INT 10" is the video interrupt. I'm sure you can manage to google the function you're looking for (i.e. X/Y pos, actual RGB color -- "R" having a span of "red", etc)



Things for you to consider... Vista creates interrupt service routines (ISR's) for all hardware interrupts. If you want to screen-paint in Vista without using the UI libraries available, you'll have to write a driver & chain the O/S ISR chain.



You can create an executable as a POSIX application and run it under a command prompt or launch it as a user-level driver. While you will get your painted screen effect, you may also get unwanted side-effects (depending on your video comtroller and its Vista driver).



All of this is "easy as pie" to implement so I won't tell you how ******* hard it is ;)
Din
2009-06-16 15:43:17 UTC
C++ doesn't natively support a great deal of low-level control, including things like turning on/off individual pixels. That's why people have written external libraries that give C++ those capabilities.



You'll want to study up on low-level programming to write your own libraries, although I don't know what you really gain except the opportunity to say 'I invented my own wheel'. Not to mention that unless you're interfacing with DirectX or OpenGL at some point you'll be utilizing software rendering instead of hardware rendering, and you won't be using all the capabilities of modern graphics processors. In short you're going to be reinventing a wheel that's light-weight but square where you can get one premade in a nice round shape but is a little heavier than you might like. If you're worried about bulky compiled binaries you might want to look for a better compiler/linker set up or study up on assembly optimization.



Anyway, C and assembly go hand-in-hand with writing libraries for higher-level languages. If you want to do all the hard work yourself those two are a good place to start.
Mike R
2009-06-16 12:13:18 UTC
I don't know how you plan on drawing something to the screen without using a tool to draw it with...


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...