Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Mi Jan 20, 2021 05:14

Foren-Übersicht » English » English Programming Forum
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 13 Beiträge ] 
Autor Nachricht
 Betreff des Beitrags: OpenGL vs DirectX - 2D Rendering.
BeitragVerfasst: Di Feb 15, 2011 09:26 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
What makes DirectX way faster at 2D rendering than OpenGL? Based on my rubbish understanding of Direct X, all you do is update some buffers which are effectively just textures. Couldn't you just have one large image in OpenGL which would be the same as the Primary Buffer in DirectX, each frame where there is a change you would modify a "Local" version of the texture and then submit that to the graphics card to update the large image at the end of the frame(And then render it to the screen)?

Or would the act of uploading a large image to the graphics card each time something changed take too long?

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Di Feb 15, 2011 10:32 
Offline
DGL Member
Benutzeravatar

Registriert: Do Dez 29, 2005 12:28
Beiträge: 2249
Wohnort: Düsseldorf
Programmiersprache: C++, C#, Java
Zitat:
Couldn't you just have one large image in OpenGL which would be the same as the Primary Buffer in DirectX

That's the framebuffer?

When using single buffering and you don't call glClear in the following frame, then image remains in the framebuffer. You just have to render your local changes into the framebuffer.
When using double buffering you have two buffers, which are swapped all the time. This is faster when you clear the buffer anyway each frame. If you don't clear the buffer you have the image of the frame before the last frame in the buffer.

You setup the use of single/double buffering when creating your OpenGL context.

_________________
Yeah! :mrgreen:


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Di Feb 15, 2011 11:02 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
I know the difference between Single and Double buffers, that has nothing to do with my question.

When you render in 2D on Direct X you are literally modifying a buffer:

Code:
LockSurf(IDDS,0,0,Width,Height,LockedData,LockedPitch); //Lock the Buffer and get its data

DoSomething(LockedData);// Modify the buffer (LockedData)

IDDS.Unlock(LockedData); //Send LockedData back to DirectX

Supposedly DirectX is far faster than OpenGL at rendering in 2D. But im asking why we can't just do the same thing in OpenGL and get similer speeds. Where you basically just use an OpenGL Texture and modify it just as you would modify DirectX's Primary Buffer if you used DirectX.

Code:
//We wouldn't need to get the texture data from OpenGL as we would store it locally.

DoSomething(LockedData);

UpdateTexture(SomeValue,LockedData);

RenderTexture(SomeValue);

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Di Feb 15, 2011 11:17 
Offline
DGL Member
Benutzeravatar

Registriert: Do Dez 29, 2005 12:28
Beiträge: 2249
Wohnort: Düsseldorf
Programmiersprache: C++, C#, Java
You should show your OpenGL code. Maybe you are doing something not the correct way. There should be no real performance difference between DirectX and OpenGL.

For example:
If you use glTexImage2D to upload your new texture data you will always cause the graphics hardware to allocate new memory and create a new texture. You should always use glTexSubImage2D when modifying an existing texture, even if you replace the whole texture.

There are more things like that.

_________________
Yeah! :mrgreen:


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Di Feb 15, 2011 11:52 
Offline
DGL Member

Registriert: Do Jun 28, 2007 17:58
Beiträge: 193
Programmiersprache: Pascal, C
The problem is, that you're looking at DirectDraw (IDDS = IDirectDrawSurface) - and DirectDraw cannot be compared to OpenGL: DirectDraw is a framework for directly accessing framebuffer memory on windows, OpenGL is a cross platform library for 3D graphics.

What you could compare is Direct3D and OpenGL. Or DirectDraw and DGA. Or DirectDraw and the SDL-Framebuffer extension. But your comparison makes no sense at all, thats like asking, why OpenGL performs that bad in playing audio compared to DirectX.

I hope that solves your question,
Andreas

_________________
http://audorra.sourceforge.net//http://andorra.sourceforge.net


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Di Feb 15, 2011 12:08 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
Coolcat hat geschrieben:
You should show your OpenGL code.

I don't have OpenGL Code.... Im going on what i have heard about the speed difference in rendering 2D as OpenGL doesn't have any 2D rendering optimisations since it renders everything in 3D.
Coolcat hat geschrieben:
For example:
If you use glTexImage2D to upload your new texture data you will always cause the graphics hardware to allocate new memory and create a new texture. You should always use glTexSubImage2D when modifying an existing texture, even if you replace the whole texture.

There are more things like that.

Never knew that, nice tip.

@igel457: Err, i know its DirectDraw. DirectX is an ambiguous term. I know that OpenGL is for 3D Graphics. I know that OpenGL can't actualy do 2D Graphics even though everyone calls it 2D Graphics. You can compare DirectDraw to OpenGL when both are rendering 2D Scenes as the visual output is the same.

Lets try again:

From what i have heard, DirectDraw can do 2D related stuff faster than OpenGL can do 2D Looking 3D Stuff. What i was wondering is why OpenGL people can't just fake what DirectDraw does and get simmiler speeds for rendering complex 2D scenes.

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Di Feb 15, 2011 12:34 
Offline
DGL Member
Benutzeravatar

Registriert: Do Dez 29, 2005 12:28
Beiträge: 2249
Wohnort: Düsseldorf
Programmiersprache: C++, C#, Java
Zitat:
From what i have heard,

That sounds like a really reliable source of information....

Zitat:
What i was wondering is why OpenGL people can't just fake what DirectDraw does and get simmiler speeds for rendering complex 2D scenes.

DirectDraw is fully 2D. You can modify a scene by just copying pixels into memory. When using OpenGL you render triangles...apply matrices, shaders and stuff like that. As igel457 said, it's a 3D API. However, when doing it correctly (*) OpenGL should be even faster than DirectDraw, since current graphics hardware is optimized for 3D.

(*) "correctly" means for example not using fixed function pipeline or the immediate mode. A few tips can be found here.

_________________
Yeah! :mrgreen:


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Di Feb 15, 2011 12:52 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
So your saying that rendering 2D Quads for everything should(TM) be faster than doing the same scene using DirectDraw? Ultimately id like to replace Original War's Ingame rendering with OpenGL, but if its going to lower the FPS then its not a great idea(There are still some users with older hardware).

Coolcat hat geschrieben:
Zitat:
From what i have heard,

That sounds like a really reliable source of information....

Well i don't want to learn DirectX so i can make a comparable test case in both API's, so i can only go on what other people tell me.

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Di Feb 15, 2011 13:08 
Offline
DGL Member

Registriert: Do Jun 28, 2007 17:58
Beiträge: 193
Programmiersprache: Pascal, C
Yes, drawing 3D-Quads for everything is a lot faster than using DirectDraw (for the same purpose). That's what my 2D-Library Andorra 2D does, which either uses Direct3D or OpenGL (the website is currently down as SF updated their hosting service).

Just one example: I used the DirectDraw-Wrapper DelphiX in one game and got around 20-30 FPS. The very same code with Andorra 2D ran at 250 FPS without doing any further optimizations.

_________________
http://audorra.sourceforge.net//http://andorra.sourceforge.net


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Di Feb 15, 2011 13:25 
Offline
DGL Member
Benutzeravatar

Registriert: Do Dez 29, 2005 12:28
Beiträge: 2249
Wohnort: Düsseldorf
Programmiersprache: C++, C#, Java
Zitat:
So your saying that rendering 2D Quads for everything should(TM) be faster than doing the same scene using DirectDraw?

Its faster in case where you can do things in hardware which where not possible in DirectDraw and therefore would have to be done in software otherwise. For example blending or multi-texturing might be faster in OpenGL. Same goes for image rotation or particle effects. However, I'm not familiar with DirectDraw and I don't know what's done on hardware and what is software. In any case the overhead due to rendering triangles instead of just copying should be minimal on OpenGL 2.x+ hardware.

Why do you have to use OpenGL? There are other APIs which are intended for hardware accelerated 2D rendering, e.g. SDL (*). This should also work on old hardware and you will get a speed comparable to DirectDraw.


Edit: (*) or Andorra 2D of course :wink:

_________________
Yeah! :mrgreen:


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Di Feb 15, 2011 14:52 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
Coolcat hat geschrieben:
Why do you have to use OpenGL?

Because i already am planning on making Original War's Menu's use an OpenGL GUI System i have been developing. Current Plan is to just replace the Menu's in Original War which would mean having both an OpenGL and a Direct X Window, where id switch between the two depending on if the user is in the Main Menu's or the actual game. So fully removing Direct X would be a nice longer term goal (And would allow my GUI system to be used in the game part as well as the menus).

Doesn't SDL just use OpenGL?

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Mi Feb 16, 2011 08:56 
Offline
DGL Member
Benutzeravatar

Registriert: Do Dez 29, 2005 12:28
Beiträge: 2249
Wohnort: Düsseldorf
Programmiersprache: C++, C#, Java
Zitat:
Doesn't SDL just use OpenGL?

You can use SDL to create an OpenGL or DirectX context, but it does also support hardware accelerate 2D graphics on its own.
Zitat:
This API supports the following features:
* single pixel points
* single pixel lines
* filled rectangles
* texture images
The primitives may be drawn in opaque, blended, or additive modes.

The texture images may be drawn in opaque, blended, or additive modes. They can have an additional color tint or alpha modulation applied to them, and may also be stretched with linear interpolation.

This API is designed to accelerate simple 2D operations. You may want more functionality such as rotation and particle effects and in that case you should use SDL's OpenGL/Direct3D support or one of the many good 3D engines.

_________________
Yeah! :mrgreen:


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Mi Feb 16, 2011 11:36 
Offline
DGL Member
Benutzeravatar

Registriert: Di Mai 18, 2004 16:45
Beiträge: 2576
Wohnort: Berlin
Programmiersprache: C/C++, C#
Since Windows Vista, the desktop system use D3D to render everything on AERO.
You get a window which contain a singe or double buffer. You can activate DoubleBuffer for every Window, to reduce the gpu usage.
The drawing Operations run over d3d.
MS use some patented technology to boost the rendering.
The moste important one is the rendering of bezier curve with fragment shader.
You only need 2 triangle to draw a perfect antialiased bezier curve in no time.
This will be used to draw round border and true type fonts on Vertex base with cheap hardware.

If you use the same technologies then you can also get the same performance with opengl.
Yes you need VBO, FBO, GLSL and yes you will fall in a performance pit if you don't use them.
Only repaint on changes else draw the front buffer.
Don't use triangle teselation or Geometry Shader to draw curves.
Use the Scissor function(cutting fonts, child components which else draw outside the parent) and draw your UI from child to root(reduce the overdraw) and not from root to child.
Avoid textures and use generated shaders for blend effects and some basic pattern.

The Windows UI use up to 7 Layer for a component like a button.

_________________
"Wer die Freiheit aufgibt um Sicherheit zu gewinnen, der wird am Ende beides verlieren"
Benjamin Franklin

Projekte: https://github.com/tak2004


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 13 Beiträge ] 
Foren-Übersicht » English » English Programming Forum


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 2 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.031s | 17 Queries | GZIP : On ]