• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
cold_heats_.--.

Float coordinates

8 posts in this topic

In SDL, how do I blit an image on the screen at floating-point coordinates?
I use SDL_BlitSurface , but it's position parameters are supposed to be SDL_Rect , which , if I'm not wrong, has integer x, y members .
0

Share this post


Link to post
Share on other sites
You're going to have to convert them to integer - more accurately "whole pixel" values. There's no such thing as the 4.72-th pixel from the left.

My guess is you want to use the floating-point coordinates to blit at interpolated locations? Usually blitting just puts pre-rendered objects (to include fully-rendered back buffers) onto the screen at screen-contextual coordinates.
0

Share this post


Link to post
Share on other sites
If you're asking how do you get from, say, screen coordinates measured (0, 0) as top-left and (1, 1) as bottom right to screen coordinates measured (0, 0) as top left and (1024, 768):

If your coordinates are (0.5, 0.25), simply multiply them by the maximum absolute integer coordinates and convert to integer.

Or: ((int)(0.5 * 1024), (int)(0.25 * 768)).

If you want something more precise, you'll have to supply more information.
0

Share this post


Link to post
Share on other sites
Well, uhm , I was asking because in a game I'm currently making, I want to set the gravity low [like 0.5], then add it to velocity, then add velocity to the coordinates from *destrect when blitting.I guess I'll just stick to integers for the moment.
0

Share this post


Link to post
Share on other sites
Sorry if I'm misunderstanding, but can't you just keep track of coordinates as floats in the background, and only convert (cast, round, whatever) to integers when it is time to blit? This is typically what I do (admittedly never used SDL, but I don't think it matters).
0

Share this post


Link to post
Share on other sites
If you really want to *blit*, you are stuck with integer coordinates. Neither SDL nor any underlying graphics API or hardware supports something different.

However, blitting is only the second best thing you can do anyway. Draw a textured quad (or two triangles) instead. Using OpenGL through SDL is well supported.
Not only does this solve your coordinate issue, but it is also fully accelerated in hardware on every card sold during almost two decades.
0

Share this post


Link to post
Share on other sites
The graphics card (driver?) does the same exact thing.

Also note that SDL 1.3 (now known as 2) renders with OpenGL, so it's probably better to use it, unless you have a special case which needs manual optimizations (like getting millions of sprites on the screen, which you will never really need).
0

Share this post


Link to post
Share on other sites
[quote name='wolfscaptain' timestamp='1341318306' post='4955259']
The graphics card (driver?) does the same exact thing.

Also note that SDL 1.3 (now known as 2) renders with OpenGL[/quote]1. No, it doesn't. It's a completely different thing.

2. Yes, but as I am trying to point out, there is a huge difference between e.g. [font=courier new,courier,monospace]glDrawPixels [/font]and [font=courier new,courier,monospace]glDrawElements[/font].

One is deprecated OpenGL 1.2 functionality, which is an entirely different pipeline (with kernels, color matrix and whatnot, see imaging subset) that has always been kind of of half-heartedly supported.
The other is the fully accelerated, native way of drawing textured geometry (such as a quad) using dedicated hardware.
Which, on my system, makes a difference of roughly 1 to 10. Your mileage may vary. Edited by samoth
0

Share this post


Link to post
Share on other sites
Normally you keep track of the object's position/velocity etc... using floats, and convert them to integers each frame when rendering. In this way you get to keep float accuracy for computations, and you only convert back to integers when you actually color pixels.

There is a way to reach subpixel level, it's called multisampling, but you don't need it now. It's notably used to "smooth out" the edges in games (anti-aliasing), but can be used to simulate the effect of a displacement of, say, half a pixel. For instance, if you were to displace a black pixel, half a pixel to the left, you would end up (theoretically) with two adjacent, gray, pixels. If you were simulating a displacement of a quarter of a pixel, you would end up with one light gray pixel, and another darker pixel. Get the idea?

But you don't need it now. Just do your logic in floating-point and render as integers, that's how it's usually done when drawing directly into pixels.
0

Share this post


Link to post
Share on other sites
[quote name='samoth' timestamp='1341323026' post='4955289']
2. Yes, but as I am trying to point out, there is a huge difference between e.g. [font=courier new,courier,monospace]glDrawPixels [/font]and [font=courier new,courier,monospace]glDrawElements[/font].

One is deprecated OpenGL 1.2 functionality, which is an entirely different pipeline (with kernels, color matrix and whatnot, see imaging subset) that has always been kind of of half-heartedly supported.
The other is the fully accelerated, native way of drawing textured geometry (such as a quad) using dedicated hardware.
Which, on my system, makes a difference of roughly 1 to 10. Your mileage may vary.
[/quote]
Neither is deprecared, and with GPU-side pixel buffers I can imagine that drawing pixel rectangles are much more efficient than before. I have not looked into pixel drawing in the modern era though, so I would like to know how modern use of pixel rectangles actually perform.

edit: Actually, I take part of the above back: glDrawPixels itself is in fact deprecated. I realized that shortly after posting. There is, however, glBlitFramebuffer for somewhat the same functionality instead. Edited by Brother Bob
0

Share this post


Link to post
Share on other sites
Thanks everyone, for the replies.Now I get the idea .
I'm using just SDL for the moment. Multisampling and textured quads are strange notions for me xD.
0

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  
Followers 0