Drawing pixels on the screen with C

  • Thread starter Thread starter Gza
  • Start date Start date
  • Tags Tags
    Drawing Screen
Click For Summary

Discussion Overview

The discussion revolves around methods for drawing pixels on the screen using the C programming language, particularly in the context of Visual C++ 6.0. Participants explore various libraries and techniques for graphical output, including both modern and older approaches.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant expresses difficulty in finding a simple putpixel(x,y) function for drawing in a DOS window using Visual C++ 6.0 and questions whether assembly language is necessary for direct video memory access.
  • Another participant mentions that modern compilers support graphics, citing Borland's "C++ Builder" with its Canvas class and Microsoft's Visual C++ using OpenGL's glDrawPixels function.
  • A suggestion is made to use the Win32 API directly for drawing in Windows mode, detailing steps to create a window and use the SetPixel function within the window's message handling procedure.
  • Links to potentially useful examples and resources are provided by a participant.
  • One participant asserts that C lacks a built-in graphical toolkit and recommends the Qt toolkit for its ease of use and power, offering assistance for getting started with it.
  • A later reply indicates that the original poster has successfully drawn on a window and expresses future intentions to develop a 3D engine for a game involving complex physics concepts.
  • Another participant suggests using SDL for its ease of learning, while also mentioning the older graphics.h library that was commonly packaged with Borland C but not with VC++ 6.0.

Areas of Agreement / Disagreement

Participants present multiple competing views on the best approach to drawing graphics in C, with no consensus on a single method or library being universally preferred.

Contextual Notes

Some participants reference specific libraries and tools that may not be available or compatible with all versions of C or Visual C++. There are also indications of varying levels of experience among participants, which may affect the applicability of certain suggestions.

Who May Find This Useful

This discussion may be useful for beginners in C programming looking to understand graphical output options, as well as those interested in developing applications that require pixel manipulation or graphical interfaces.

Gza
Messages
446
Reaction score
0
Okay, from the title of this post, you can already tell I'm pretty much a noob when it comes to C. But the situation is that I have visual c++ 6.0, and haven't been able to find any libraries with a putpixel(x,y) type function that i can use to simply plot a point within a dos window. Would i have to use some assembly to do this and mess with video memory directly? thanks for the feedback.
 
Computer science news on Phys.org
What compiler are you using? It used to be that most computer monitors did not support graphics so graphics methods were not routinely included in compilers.

More modern compilers support "windows" type graphics. In particular, Borland's "C++ Builder" has the "Canvas" class that includes the method "Canvas->Pixels[j] that sets pixels at screen coords (i,j). MicrosSoft's, "Visual C++" uses "OpenGL" that includes the command "glDrawPixels(i,j)".
 
Do you want to draw in windows mode? There are several ways to accomplish this. If you you like C's procedural feel you can use the Win32 API directly without the MFC C++ OO-encapsulation classes. The basic way to acomplish this is to:.

1. Create a window, using the CreateWindow(...) function retaining the "handle" (pointer) that window
2. There is a window message handling procedure called "WndProc", which is called everytime the window receives a message (like being told to destroy itself). You need to get the "graphics" handle for the Window. This can be done in few ways, but the wizard included in the version of VC++ that I have uses a simple procedure called "BeginPaint". Looks like they learned their lesson from Java!
3. Use the "SetPixeL" function on the graphics handle of the window .

Visual C++ includes a "wizard" called "Win32 Application" which gives you a good chunk of the code that you need to accomplish this. It gives you a handle to the window it creats called "hWnd". You would then probably put your drawing functions in the WM_PAINT case of the "WndProc" procedure which handles window messages. It even gives you the handle to device context "hdc". You would then use the SetPixel function to accomplish your drawing.
 
Possibly useful examples:

http://www.codeguru.com/forum/showthread.php?t=338284&goto=nextoldest
http://cis.stvincent.edu/swd/graphics/graphics.html
 
Last edited by a moderator:
C has no built-in graphical toolkit whatsoever, so you cannot, by definition, do what you're doing in C alone. You will need a library to accomplish drawing to the screen. I strongly recommend the Qt toolkit -- it's free for non-commercial use, easy as pie to use, and very, very powerful. You will not find a toolkit that's better designed or more easy-to-use. http://www.trolltech.com/download/qt/evaluate.html

If you need any help getting started with Qt or any other graphical toolkit, please ask for help -- I, as well as many others here, can help you.

- Warren
 
Last edited by a moderator:
thanks chroot and everyone else for your valuable advice and resources. I'm now able to draw on a window. I'll come back here to ask more questions when i begin work on my fully immersive 3d-engine for a massively multiplayer online game, with motion dictated by true to life physics, involving fields from general relativity to quantum mechanics. :smile:
 
Oh, I thought everyone had one of those lying about someplace.
 
go with SDL its very easy to learn...but if your looking for the simplest library...
its graphics.h(and prolly one fo the oldest)...it was usually packaged with C(borland) but VC++6.0 took it out. I can send you the old version.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 16 ·
Replies
16
Views
5K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 52 ·
2
Replies
52
Views
8K
  • · Replies 19 ·
Replies
19
Views
9K
  • · Replies 1 ·
Replies
1
Views
9K
Replies
12
Views
4K