|
I'm trying to call glGenLists and it fails with the GL_INVALID_OPERATION error.
The error description (from MSDN) says that the glGenLists falls between a glBegin and its glEnd .
I have many glBegin and glEnd in my program; is there a way to :
- know when that call was done (i.e. after which glBegin , if it's of any use ?
- or to synchronize things up so that the glGenLists does not fall between the 2 calls ?
--------------
Solution :
I just needed to put my code at the beginning of the OnDraw of my view that reacts to a boolean that states the font change
(for example pseudo-ish-code)
OnChangeFont( int iSize )
{
m_bChangeFont = true;
m_iFontSize = iSize;
}
OnDraw(CDC* pDC)
{
if ( m_bChangeFont)
{
DoTheFontChange();
m_bChangeFont = false;
}
DrawTheScene();
}
Thanks.
Max
Last modified: 34mins after originally posted --
|
|
|
|
|
Hi,
I have a drawing routine in a class, two different object instances are alive:
void MyClass::DrawThumb(HDC hdc, RECT rc)
{
static Gdiplus::Bitmap bmThumb(m_hResource, MAKEINTRESOURCE(IDB_THUMB));
Gdiplus::Graphics gr(hdc);
gr.DrawImage(&bmThumb, rc.left, rc.top);
}
This compiles (VS2008) and runs OK under Vista but crashes on some Vista systems when the final destruction is happening i.e. end of _crtMain().
What is the problem?
Thanks,
AR
|
|
|
|
|
Why is drawing code getting called during destruction?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks Mark,
I got the answer with Jim Barry's help.
Mark Salsbery wrote: Why is drawing code getting called during destruction?
The static Gdiplus::Bitmap bmThumb destructor runs after GdiplusShutdown has been called, resulting in undefined behaviour.
To use this kind of construct I have to GdiplusStartup() and GdiplusShutdown() inside a static object instanciated at the very beginning of app creation, and deleted at the very end for instance:
#include "stdafx.h"
class GdiPlusUser
{
ULONG _Token;
public:
GdiPlusUser() : _Token(0)
{
Gdiplus::GdiplusStartupInput input;
VERIFY(Gdiplus::GdiplusStartup(&_Token, &input, NULL) == Gdiplus::Ok);
}
~GdiPlusUser()
{
ASSERT(_Token);
Gdiplus::GdiplusShutdown(_Token);
}
} _GdiPlusUser;
Then no more crash, on XP or Vista.
cheers,
AR
modified on Tuesday, July 29, 2008 12:15 AM
|
|
|
|
|
Cool Thanks for the update!
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I was wondering if there was a code for programing shapes and images. Tell me if this is the wrong forum for this question. Here is an example of the "code"
< g >
< circle fill-="none" stroke-="#231F20" >
Then it goes on about stroke width, cx, cy, and r
|
|
|
|
|
Looks like SVG[^].
Citizen 20.1.01 'The question is,' said Humpty Dumpty, 'which is to be master - that's all.'
|
|
|
|
|
RotaryAce wrote: I was wondering if there was a code for programing shapes and images
In which language/programing environment ?
|
|
|
|
|
if your using .Net all you do is use the paint method of the control youd like to paint on like so...
OnPaint(object sender, PaintEventArgs e)
{
e.Graphics.FillEllipse(someBrush, someRectangle);
}
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.passion != Programming)
|
|
|
|
|
Hi,
I am building a graph to render the MPEG1 format file using Smart Tee filter. But it is not showing the preview properly. However the capture pin is working properly.
Is it because of the decoder which i am using. Actually i tried with FFDShow, MPEG decoders.
Please let me know how to resolve this issue.
Thanks in advance.
Kuldeep
|
|
|
|
|
What does the filter graph look like?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I cannot attach the screenshot but the Graphs looks like this
Mpeg File
---> Mepeg1Splitter-->Audio------->FFDSHow Audio Decoder->Audio File
--->Mepeg1Splitter--->Video --->Smart Tee Filter
--->Smart Tee Filter-->Capture-->FFDShow Video Decoder---> WMV File
|
|--->Preview->MPEG Video Decoder---->Video Renderer
|
|
|
|
|
What about decoding the video stream before the smart tee?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
For MPEG-2 the Graphs are build properly. But still there is problem in Running the GRAPH if the output is WM ASF Writer Filter. Even in GraphEdit it is giving the error. Here is the graph for MPEG-2
Instead of WM ASF Writer if we use Video Renderer then the video is rendered properly. But it is not working in case of WM ASF Writer filter. Can you please look into this and give your comment on this?
|
|
|
|
|
One more point. The source video which i am using does not contain any audio. Will it matter while running the graph.
|
|
|
|
|
I wish to capture some live video and preview, but PlayVideoCap example that i downloaded from Windows SDK, (DirectX) just doesn't do the job. It compiles and there is no error messages. video preview show black screen,although avi frame capturing works fine.. and video capture with VideoCap works. I wish to capture from the Capture Card as well and currently using a surveillance camera.
I am beginner in video programming C++. What possibilities of mistakes there may be? Any advice please! Any other sample codes??
Thanks in advance.
Cheers,
kel
any help is greatly appreciated.
|
|
|
|
|
What O/S are you using? I understand some of the older video functions have been dropped in Vista. For instance, part of the capture functionality in OpenCV depends on Video For Windows and doesn't work on Vista.
If you don't have the data, you're just another a**hole with an opinion.
|
|
|
|
|
Thank you for your response...
i am using windows XP os.
and i've met the requirements of the capture card itself..
so wad could be the problem?
the sample codes maybe?
Regards,
Kel
|
|
|
|
|
My only experience in that area is to use OpenCV which you can find on Source Forge. It includes some examples and has all the code including the lower level pieces that they use to interface with the cameras. There are several articles here on CP that use it also.
If you don't have the data, you're just another a**hole with an opinion.
|
|
|
|
|
Is PlayVideoCap a DirectShow sample? If so, DirectShow should
work for your application. It will take some study if you're
a beginner, but there's enough sample code in the DirectShow SDK
to get an app up and working.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Use a more descriptive subject line next time
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi there ,
I'm trying to develop a ray tracing software in c++ by the help of "Ray Tracing from ground up" book by Kevin Suffern.
Here is a sample of the program :
World::render_scene(void) {
RGBColor pixel_color;
Ray ray;
double zw = 100.0;
double x,y;
open_window(vp.hres,vp.vres);
ray.d = Vector3D(0,0,-1);
for ( int r = 0;r< vp.vres;r++)
for (int c = 0;c<=vp.hres;c++){
x = vp.s * (c - 0.5 * (vp.hres - 1.0));
y = vp.s * (r - 0.5 * (vp.vres - 1.0));
ray.o = Point3D(x,y,zw) ;
pixel_color = tracer_ptr->trace_ray(ray);
display_pixel(r,c,pixel_color);
}
}
My question is what to write inside open_window body and also display_pixel in order to create a window that contain an image .
Regards ,
Ahmad
|
|
|
|
|
Okay, here it goes...
[My rant]
I've been searching for weeks now on how to work with 2D images in DirectX using C#. However, I've been completely unsuccessful in doing so. The help files that come with DirectX are horrible because they are organized by classes and such. Meaning that a person like me who has never worked with DirectX before, will be completely lost. The help files should take you through DirectX in order of complexity, showing you the simplest things first, but they don't. They are more like a reference guide. But, anyways they are no help to DirectX newbies like me.
I've looked around on the internet a lot trying to get some information on this topic and then attempting to piece it together. However, I've been completely unsuccessful. 90% of all examples are using out-dated versions of DirectX, meaning they are irrelevant to me. The other 10% are either in C++, which I do not understand.
I've seen some rare occurrences of 2D DirectX projects in C#, but they are using older versions of C#, which didn't fully support DirectX and were workarounds (so they've said). When I try to convert them to the newest version of a C# solution they fail to compile.
There is a sample that comes with DirectX that supposed to show you how to perform "Simple 2D". However, it actually not very simple and is a rather large project in my world. But, the killer is that it also fails to run on my computer, most likely because they are trying to use some advanced feature when its supposed to be "Simple 2D". I'm pretty sure my computer is capable of displaying some 2D images and then move them around a little.
[/My rant]
So that's enough of my complaining, I just wanted anyone who reads this thread to know that I did try to figure this out on my own before coming here.
Basically what I'm asking for is for someone to either explain to me very simply how to get a basic 2D C# project using DirectX up and running or create one for me so I can pick it apart and try to figure out what's going on.
I only want the simplest example. Like displaying some 2D images and maybe moving them around or rotating them. Nothing fancy.
Many thanks in advance to anyone who can help me out. 
|
|
|
|
|
I still need help on this topic, but to make it easier for someone to help me I put together a project myself. However, it should be working, but its not; The image never shows up on the form.
Here's the link to the project files:
http://www.freewebs.com/thrash505/2D_DirectX9_Test.zip
Program.cs
#region Using Directives
using System;
using System.Windows.Forms;
#endregion
namespace _2D_DirectX9_Test {
#region Program Class
public static class Program {
[STAThread]
public static void Main( ) {
GameForm gameForm = new GameForm( );
gameForm.Show( );
while( gameForm.Created ) {
gameForm.RenderGraphics( );
Application.DoEvents( );
}
}
}
#endregion
}
GameForm.cs
#region Using Directives
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
#endregion
namespace _2D_DirectX9_Test {
#region GameForm Class
public partial class GameForm : Form {
#region GameForm - Attributes
private Device _graphicsDevice;
private Sprite _spriteManager;
private GraphicsSprite gs;
#endregion
#region GameForm - Properties
private Device GraphicsDevice {
get { return _graphicsDevice; }
set { _graphicsDevice = value; }
}
private int ScreenWidth {
get { return 1024; }
}
private int ScreenHeight {
get { return 768; }
}
public Sprite SpriteManager {
get { return _spriteManager; }
set { _spriteManager = value; }
}
#endregion
#region GameForm - Constructors
public GameForm( ) {
InitializeComponent( );
InitializeGraphics( );
}
#endregion
#region GameForm - Methods
private void InitializeGraphics( ) {
PresentParameters presentParameters = new PresentParameters( );
Format currentFormat = Manager.Adapters[ 0 ].CurrentDisplayMode.Format;
presentParameters.SwapEffect = SwapEffect.Discard;
if( Manager.CheckDeviceType( 0, DeviceType.Hardware, currentFormat, currentFormat,
false ) ) {
presentParameters.Windowed = true;
presentParameters.BackBufferFormat = currentFormat;
presentParameters.BackBufferCount = 1;
presentParameters.BackBufferWidth = ScreenWidth;
presentParameters.BackBufferHeight = ScreenHeight;
} else {
presentParameters.Windowed = true;
}
GraphicsDevice = new Device( 0, DeviceType.Hardware, this,
CreateFlags.SoftwareVertexProcessing, presentParameters );
SpriteManager = new Sprite( GraphicsDevice );
gs = new GraphicsSprite( new Vector3( 0f, 0f, 1f ),
TextureLoader.FromFile( GraphicsDevice, @"C:\music_player.png" ) );
}
public void RenderGraphics( ) {
_spriteManager.Begin( SpriteFlags.AlphaBlend );
gs.Draw( SpriteManager );
_spriteManager.End( );
}
private void GameForm_KeyUp( object sender, KeyEventArgs e ) {
if( e.KeyCode == Keys.Escape )
this.Close( );
}
#endregion
}
#endregion
}
GraphicsSprite.cs
#region Using Directives
using System;
using System.Drawing;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
#endregion
namespace _2D_DirectX9_Test {
#region GraphicsSprite Class
public class GraphicsSprite {
#region GraphicsSprite - Attributes
private Vector3 _center;
private Vector3 _position;
private Rectangle _sourceRectangle;
private Texture _texture;
#endregion
#region GraphicsSprite - Properties
public Vector3 Center {
get { return _center; }
set { _center = value; }
}
public Vector3 Position {
get { return _position; }
set { _position = value; }
}
public Rectangle SourceRectangle {
get { return _sourceRectangle; }
set { _sourceRectangle = value; }
}
public Texture Texture {
get { return _texture; }
set { _texture = value; }
}
#endregion
#region GraphicsSprite - Constructors
public GraphicsSprite( Vector3 position ) {
Center = new Vector3( 0, 0, 0 );
Position = position;
}
public GraphicsSprite( Vector3 center, Vector3 position ) {
Center = center;
Position = position;
}
public GraphicsSprite( Vector3 center, Vector3 position, Texture texture ) {
SurfaceDescription surfaceDescription;
Center = center;
Position = position;
Texture = texture;
surfaceDescription = Texture.GetSurfaceLevel( 0 ).Description;
SourceRectangle = new Rectangle( 0, 0, surfaceDescription.Width,
surfaceDescription.Height );
}
public GraphicsSprite( Vector3 position, Texture texture ) {
SurfaceDescription surfaceDescription;
Center = new Vector3( 0, 0, 0 );
Position = position;
Texture = texture;
surfaceDescription = Texture.GetSurfaceLevel( 0 ).Description;
SourceRectangle = new Rectangle( 0, 0, surfaceDescription.Width,
surfaceDescription.Height );
}
#endregion
#region GraphicsSprite - Methods
public void Draw( Sprite spriteManager ) {
spriteManager.Draw( Texture, SourceRectangle, Center, Position, Color.White );
}
#endregion
#endregion
}
}
Thanks again to anyone who can help me.
|
|
|
|
|
 I've finally figured out why my code wasn't working... I had to set the view transform and turn off lighting. Then I had to put in the BeginScene(), EndScene(), and Present() calls when rendering.
Here's the new version of the GameForm.cs file:
#region Using Directives
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
#endregion
namespace _2D_DirectX9_Test {
#region GameForm Class
public partial class GameForm : Form {
#region GameForm - Attributes
private Device _graphicsDevice;
private Sprite _spriteManager;
private GraphicsSprite gs;
#endregion
#region GameForm - Properties
private Device GraphicsDevice {
get { return _graphicsDevice; }
set { _graphicsDevice = value; }
}
private int ScreenWidth {
get { return 1024; }
}
private int ScreenHeight {
get { return 768; }
}
public Sprite SpriteManager {
get { return _spriteManager; }
set { _spriteManager = value; }
}
#endregion
#region GameForm - Constructors
public GameForm( ) {
InitializeComponent( );
InitializeGraphics( );
}
#endregion
#region GameForm - Methods
private void InitializeGraphics( ) {
PresentParameters presentParameters = new PresentParameters( );
Format currentFormat = Manager.Adapters[ 0 ].CurrentDisplayMode.Format;
presentParameters.SwapEffect = SwapEffect.Discard;
if( Manager.CheckDeviceType( 0, DeviceType.Hardware, currentFormat, currentFormat,
false ) ) {
presentParameters.Windowed = true;
presentParameters.BackBufferFormat = currentFormat;
presentParameters.BackBufferCount = 1;
presentParameters.BackBufferWidth = ScreenWidth;
presentParameters.BackBufferHeight = ScreenHeight;
} else {
presentParameters.Windowed = true;
}
GraphicsDevice = new Device( 0, DeviceType.Hardware, this,
CreateFlags.SoftwareVertexProcessing, presentParameters );
GraphicsDevice.Transform.View = Matrix.OrthoOffCenterLH( 0, ScreenWidth, ScreenHeight, 0, 0, 10 );
GraphicsDevice.RenderState.Lighting = false;
SpriteManager = new Sprite( GraphicsDevice );
gs = new GraphicsSprite( new Vector3( 0f, 0f, 1f ),
TextureLoader.FromFile( GraphicsDevice, @"C:\test.bmp" ) );
}
public void RenderGraphics( ) {
GraphicsDevice.Clear( ClearFlags.Target, Color.FromArgb( 0, 0, 225 ), 0, 0 );
GraphicsDevice.BeginScene( );
_spriteManager.Begin( SpriteFlags.AlphaBlend );
gs.Draw( SpriteManager );
_spriteManager.End( );
GraphicsDevice.EndScene( );
GraphicsDevice.Present( );
}
private void GameForm_KeyUp( object sender, KeyEventArgs e ) {
if( e.KeyCode == Keys.Escape )
this.Close( );
}
#endregion
}
#endregion
}
Hopefully that will help somebody else.
|
|
|
|
|