Sign in to follow this  
RexHunter99

OpenGL Draw Image (Not Textures) to screen

Recommended Posts

RexHunter99    100
Hey guys, I might be asking something stupid but the similarities between OpenGL and Direct3D9 are being swamped by the differences. In my project I have a bunch of image resources (specifically 565 16-bit images) that are not square or power of 2 most of the time and I know that not all machines support using a non-square or not power of 2 texture, In OpenGL it's as simple as calling glDrawPixels()... but from my understanding of Direct3D9 thus far, it may not be as simple as that for me. I did find a few pages regarding D3DX and Sprites but I'm not that far into fully understanding DirectX, and I'm just trying to learn plain D3D9 on it's own for the time being, also I have little to no choice in either changing the resources to work better as textures nor am I able to link D3DX to my project (I'm using GNU GCC MinGW, it produces much smaller executables and they seem to run marginally faster than the MSVC++ 2008 executables, as well as the fact they don't seem so prone to crashing with the bad programming done back in the late 90s on the game engine I'm trying to ramp up) I'll give a few details as to why I'm in such a sticky situation with these restrictions, I've got the source-code (legit) to an old game, I've begun rewriting the D3D7 code into D3D9 and thus far there have been no Direct3D related crashes on any system this game has been tested on since the upgrade, I'm still a ways off completing this, but before I move onto managing the textures for the game geometry, I want to have the User Interface working (the default game code already prints out quite a bit of useful information to the screen and I need some of these image resources to work) Basically all I want to do is take the Image data (whether it be RGB's RGBA's or 565) and print it onto the screen directly in a fashion that does not temporarily stall the game as writing to the backbuffer does (Locking the back buffer causes a stall that is considerably noticeable even at 640x480 resolution, which is absolutely unacceptable.) Also note I'm on a 5 year old machine, and I want this game to work on new computers, but also old ones, so fixes that only work on new system are unacceptable. Also, this fits into the same subject, I want to be able to print a single pixel out on the screen, don't worry, I don't intend to draw any more than 100 or sow pixels manually, but if D3D7 could do it easily... why shouldn't D3D9 be able to? OpenGL has allowed me to do it as well. Thank you all in advance if you answer, your help is appreciated when given :)

Share this post


Link to post
Share on other sites
Evil Steve    2017
Quote:
Original post by RexHunter99
Basically all I want to do is take the Image data (whether it be RGB's RGBA's or 565) and print it onto the screen directly in a fashion that does not temporarily stall the game as writing to the backbuffer does (Locking the back buffer causes a stall that is considerably noticeable even at 640x480 resolution, which is absolutely unacceptable.) Also note I'm on a 5 year old machine, and I want this game to work on new computers, but also old ones, so fixes that only work on new system are unacceptable.

Also, this fits into the same subject, I want to be able to print a single pixel out on the screen, don't worry, I don't intend to draw any more than 100 or sow pixels manually, but if D3D7 could do it easily... why shouldn't D3D9 be able to? OpenGL has allowed me to do it as well.
Why use D3D9 for this then? It sounds like you either want DirectDraw, or you'll need to do a bit of work to get it to work on D3D9. I don't know why OpenGL would be faster, locking the backbuffer should be pretty much the same performance as calling glDrawPixels (So long as you lock with the correct flags).

I'd create a surface (not a texture), LockRect() it at the start of the frame, draw whatever you like into it manually, then UnlockRect() and call UpdateSurface to copy it to the backbuffer.

Share this post


Link to post
Share on other sites
RexHunter99    100
How fast does that work? glDrawPixels() is fast enough that the framerate is visibly unaffected (it drops but the human eye will never notice unless the hardware you run the game on is really old)

The original D3D7 code Locked the backbuffer surface, dropped the image onto it, then Unlocked the surface, of course D3D is much different now than it was then... but I am trying as hard as I can to avoid putting in any unessecary libraries and if the method you've supplied with UpdateSurface won't visible affect an already good frame rate, then I'll use it.

Share this post


Link to post
Share on other sites
HuntsMan    368
No, glDrawPixels is still slow, it was removed from modern versions of OpenGL for that reason. Using textures is the way to go.

Share this post


Link to post
Share on other sites
RexHunter99    100
So what do I do about users who have Graphics Hardware that do not allow non-square/power-of-2 textures? waste texture space by generating a power of 2 (and square if I must) texture and Blt the data to that? That's a waste tbh and I'm trying my best to support new and old machines (said so above)

glDrawPixels() does not visibly stall my hardware which is quite old, so I'm happy with saying it's not too slow (yes, in truth it is slow, but in the application it isn't really slow enough to matter since I'm not doing anything advanced)

Share this post


Link to post
Share on other sites
Evil Steve    2017
Quote:
Original post by RexHunter99
The original D3D7 code Locked the backbuffer surface, dropped the image onto it, then Unlocked the surface, of course D3D is much different now than it was then... but I am trying as hard as I can to avoid putting in any unessecary libraries and if the method you've supplied with UpdateSurface won't visible affect an already good frame rate, then I'll use it.
D3D7 and D3D9 are pretty similar under the hood for direct backbuffer access - I wouldn't expect much in the way of performance differences from doing something like locking the backbuffer - which will be slow no matter how you do it.
UpdateSurface() is probably the fastest way to update the backbuffer directly.

Quote:
Original post by RexHunter99
So what do I do about users who have Graphics Hardware that do not allow non-square/power-of-2 textures? waste texture space by generating a power of 2 (and square if I must) texture and Blt the data to that? That's a waste tbh and I'm trying my best to support new and old machines (said so above)
If you're using the UpdateSurface method, you're not using textures, so this doesn't apply. The power-of-2 and square restrictions only apply to textures, not surfaces.

Share this post


Link to post
Share on other sites
RexHunter99    100
It'll be too much of a hassle to use UpdateSurface, I'd have to completely rebuild how t he entire game works (and I will try out every option to me before I begin rewriting around 6000 lines of code out of 20,000+)

Looks like LPD3DXSPRITE might be something I'll have to use... now if only I could get the damn D3DX headers to work with MinGW in Code::Blocks >_>
Has this problem been solved before? MinGW dislikes the "SUB" at the end of the header IIRC, and MinGW only comes with outdated standard d3d7,8,9 headers, no D3DX...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By povilaslt2
      Hello. I'm Programmer who is in search of 2D game project who preferably uses OpenGL and C++. You can see my projects in GitHub. Project genre doesn't matter (except MMO's :D).
    • By ZeldaFan555
      Hello, My name is Matt. I am a programmer. I mostly use Java, but can use C++ and various other languages. I'm looking for someone to partner up with for random projects, preferably using OpenGL, though I'd be open to just about anything. If you're interested you can contact me on Skype or on here, thank you!
      Skype: Mangodoor408
    • By tyhender
      Hello, my name is Mark. I'm hobby programmer. 
      So recently,I thought that it's good idea to find people to create a full 3D engine. I'm looking for people experienced in scripting 3D shaders and implementing physics into engine(game)(we are going to use the React physics engine). 
      And,ye,no money =D I'm just looking for hobbyists that will be proud of their work. If engine(or game) will have financial succes,well,then maybe =D
      Sorry for late replies.
      I mostly give more information when people PM me,but this post is REALLY short,even for me =D
      So here's few more points:
      Engine will use openGL and SDL for graphics. It will use React3D physics library for physics simulation. Engine(most probably,atleast for the first part) won't have graphical fron-end,it will be a framework . I think final engine should be enough to set up an FPS in a couple of minutes. A bit about my self:
      I've been programming for 7 years total. I learned very slowly it as "secondary interesting thing" for like 3 years, but then began to script more seriously.  My primary language is C++,which we are going to use for the engine. Yes,I did 3D graphics with physics simulation before. No, my portfolio isn't very impressive. I'm working on that No,I wasn't employed officially. If anybody need to know more PM me. 
       
    • By Zaphyk
      I am developing my engine using the OpenGL 3.3 compatibility profile. It runs as expected on my NVIDIA card and on my Intel Card however when I tried it on an AMD setup it ran 3 times worse than on the other setups. Could this be a AMD driver thing or is this probably a problem with my OGL code? Could a different code standard create such bad performance?
    • By Kjell Andersson
      I'm trying to get some legacy OpenGL code to run with a shader pipeline,
      The legacy code uses glVertexPointer(), glColorPointer(), glNormalPointer() and glTexCoordPointer() to supply the vertex information.
      I know that it should be using setVertexAttribPointer() etc to clearly define the layout but that is not an option right now since the legacy code can't be modified to that extent.
      I've got a version 330 vertex shader to somewhat work:
      #version 330 uniform mat4 osg_ModelViewProjectionMatrix; uniform mat4 osg_ModelViewMatrix; layout(location = 0) in vec4 Vertex; layout(location = 2) in vec4 Normal; // Velocity layout(location = 3) in vec3 TexCoord; // TODO: is this the right layout location? out VertexData { vec4 color; vec3 velocity; float size; } VertexOut; void main(void) { vec4 p0 = Vertex; vec4 p1 = Vertex + vec4(Normal.x, Normal.y, Normal.z, 0.0f); vec3 velocity = (osg_ModelViewProjectionMatrix * p1 - osg_ModelViewProjectionMatrix * p0).xyz; VertexOut.velocity = velocity; VertexOut.size = TexCoord.y; gl_Position = osg_ModelViewMatrix * Vertex; } What works is the Vertex and Normal information that the legacy C++ OpenGL code seem to provide in layout location 0 and 2. This is fine.
      What I'm not getting to work is the TexCoord information that is supplied by a glTexCoordPointer() call in C++.
      Question:
      What layout location is the old standard pipeline using for glTexCoordPointer()? Or is this undefined?
       
      Side note: I'm trying to get an OpenSceneGraph 3.4.0 particle system to use custom vertex, geometry and fragment shaders for rendering the particles.
  • Popular Now