473,395 Members | 1,885 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Basic graphics

Hey guys

I have an app front end in directx, but have decided since my graphics are
so basic and my app always runs windowed that removing direct x and using
standard graphics functionality is better.

In directx i have a texture file full of images and i can take a rectangular
region and display it, then move to the next rectangle and display it etc.

So i would like to do the same using, i presume gdi which should use a lot
less cpu power i presume?Can gdi do this, take a rectangular region of a
file and blit it to the screen? So that i can do everything i did in directx
in gdi?

Any tips or tutorials would be great

Dan
Jul 1 '06 #1
3 1760
On Sat, 1 Jul 2006 13:59:18 +0100, Daniel wrote:
In directx i have a texture file full of images and i can take a rectangular
region and display it, then move to the next rectangle and display it etc.

So i would like to do the same using, i presume gdi which should use a lot
less cpu power i presume?
Not necessarily. GDI+ does not yet support hardware acceleration so it
might not be as fast as DirectX and might not use less CPU power. For
simple drawing though, it does the job just fine and is it's really easy to
use (i've never used DirectX but i'm working on DirectShow at the moment
and if that's the same mess in DirectX then you'll be more than happy to
switch to GDI+).
Can gdi do this, take a rectangular region of a
file and blit it to the screen? So that i can do everything i did in directx
in gdi?
I'm not too sure of what you want to do here. If you've got an image file
and want to draw part of the image on a Form or a Control, use the Image
class to load to image then use the Graphics.DrawImage() or
Graphics.DrawImageUnscaled() to draw all or part of the image on whatever
drawing surface you want to draw (this can be a Control's surface or a
Bitmap object).
Any tips or tutorials would be great


The reference for all GDI+ stuff is Bob Powell's FAQ:
<http://www.bobpowell.net/faqmain.htm>. He's got a beginner's guide too.
The appropriate forum for GDI+ drawing is
microsoft.public.dotnet.framework.drawing
Jul 1 '06 #2
Hey

Thanks for the advice. My directx scene runs a game loop and that therefore
uses as much cpu power as is available.

When i referred to the rectangular region, i am referring to taking a bmp
say, and on that bitmap of say 512x512 pixels i can have say frame one of an
animation on the first 32x32, then frame 2 on the next 32x32 etc, then when
i want to show frame one i take rectangular region of 32x32 in position 0,0
then for frame 2 take the same 32x32 size but starting at position 32,0,
frame 2.

I will see if i cant get the cpu usage down, maybe i will stick with my
directx setup, its working great just worried about if i have a bit of
overkill.

"Mehdi" <vi****@REMOVEME.gmail.comwrote in message
news:2t*****************************@40tude.net...
On Sat, 1 Jul 2006 13:59:18 +0100, Daniel wrote:
>In directx i have a texture file full of images and i can take a
rectangular
region and display it, then move to the next rectangle and display it
etc.

So i would like to do the same using, i presume gdi which should use a
lot
less cpu power i presume?

Not necessarily. GDI+ does not yet support hardware acceleration so it
might not be as fast as DirectX and might not use less CPU power. For
simple drawing though, it does the job just fine and is it's really easy
to
use (i've never used DirectX but i'm working on DirectShow at the moment
and if that's the same mess in DirectX then you'll be more than happy to
switch to GDI+).
>Can gdi do this, take a rectangular region of a
file and blit it to the screen? So that i can do everything i did in
directx
in gdi?

I'm not too sure of what you want to do here. If you've got an image file
and want to draw part of the image on a Form or a Control, use the Image
class to load to image then use the Graphics.DrawImage() or
Graphics.DrawImageUnscaled() to draw all or part of the image on whatever
drawing surface you want to draw (this can be a Control's surface or a
Bitmap object).
>Any tips or tutorials would be great

The reference for all GDI+ stuff is Bob Powell's FAQ:
<http://www.bobpowell.net/faqmain.htm>. He's got a beginner's guide too.
The appropriate forum for GDI+ drawing is
microsoft.public.dotnet.framework.drawing

Jul 1 '06 #3
On Sat, 1 Jul 2006 22:14:29 +0100, Daniel wrote:
Thanks for the advice. My directx scene runs a game loop and that therefore
uses as much cpu power as is available.

When i referred to the rectangular region, i am referring to taking a bmp
say, and on that bitmap of say 512x512 pixels i can have say frame one of an
animation on the first 32x32, then frame 2 on the next 32x32 etc, then when
i want to show frame one i take rectangular region of 32x32 in position 0,0
then for frame 2 take the same 32x32 size but starting at position 32,0,
frame 2.

I will see if i cant get the cpu usage down, maybe i will stick with my
directx setup, its working great just worried about if i have a bit of
overkill.
I honestly don't know whether this would be less CPU intensive with GDI+ or
not but it takes only a few seconds to do that with GDI+: add a new form to
you project, replace the code with the following (untested) code and
display the form.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace Whatever
{
public class Form1 : System.Windows.Forms.Form
{
private System.ComponentModel.IContainer components;

private const string ImagePath = "image.bmp";
private const int FrameRate = 10; // 10 frames per second

private Image m_image = null;
private int m_nextX = 0;
private int m_nextY = 0;
private System.Windows.Forms.Timer frameTimer;

public Form1()
{
InitializeComponent();

// Set double buffering to avoid flickering
this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.UserPaint |
ControlStyles.DoubleBuffer |
ControlStyles.ContainerControl |
ControlStyles.ResizeRedraw, true);
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code

private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.frameTimer = new System.Windows.Forms.Timer(this.components);
//
// frameTimer
//
this.frameTimer.Interval = 500;
this.frameTimer.Tick += new System.EventHandler(this.frameTimer_Tick);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.Paint += new
System.Windows.Forms.PaintEventHandler(this.Form1_ Paint);

}
#endregion

private void Form1_Load(object sender, System.EventArgs e)
{
// Load the image file
m_image = Image.FromFile(ImagePath);
// Start the timer
frameTimer.Interval = 1000 / FrameRate;
frameTimer.Start();
}

private void frameTimer_Tick(object sender, System.EventArgs e)
{
// When the timer ticks, ask the form to redraw itself
// (draw the next frame)
this.Invalidate();
}

private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs
e)
{
// Paint the next frame
e.Graphics.DrawImage(m_image,
0, 0,
new Rectangle(m_nextX, m_nextY, 32, 32),
GraphicsUnit.Pixel);

// Compute the coordinates of the origin of the following frame
m_nextX += 32;
if (m_nextX + 32 m_image.Width)
{
// We've finished this line of images, go to the next line
m_nextX = 0;
m_nextY += 32;
if (m_nextY + 32 m_image.Height)
{
// We've reached the end of the images, loop back
// to the begining
m_nextY = 0;
}
}
}
}
}
Jul 2 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Malcolm | last post by:
After some days' hard work I am now the proud possessor of an ANSI C BASIC interpreter. The question is, how is it most useful? At the moment I have a function int basic(const char *script,...
56
by: Dave Vandervies | last post by:
I just fixed a bug that some of the correctness pedants around here may find useful as ammunition. The problem was that some code would, very occasionally, die with a segmentation violation...
4
by: Dave | last post by:
Hi, Is there anyway to mimic forms authentication's loginUrl and RedirectFromLoginPage functionality using Windows authentication? We are developing intranet sites using basic authentication...
2
by: Kay Warner | last post by:
I am having problems with persistant graphics, when I reduce a form to an Icon I loose my picture.I understand that graphics objects have no memory and you have to place the code in the paint...
3
by: Stephen | last post by:
hi, i would like to draw static arrows in the window form. Seems from the posts that there isnt any drawing toolbox. Is there a way of doing it? Pls go step by step, this is the first time i...
0
by: Dr. Zharkov | last post by:
Hello. To see the graphics of technology DirectX 9.0 SDK Update - June 2005 in project Visual Basic, WindowsApplication1 from Visual Studio 2005 Beta 1, in file My Project, MyApplication.vb in a...
97
by: Master Programmer | last post by:
An friend insider told me that VB is to be killled off within 18 months. I guess this makes sence now that C# is here. I believe it and am actualy surprised they ever even included it in VS 2003 in...
3
by: KiranJyothi | last post by:
Hello everybody, While I am doing the program( pasted below ), I am able to see the frame but not the rectangles. Can anyone please help me to get it done. Thanks in...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.