A structure that defines a two dimensional point.
int |
x |
the x coordinate of the point |
int |
y |
the y coordinate of the point |
// Example program:
// Using SDL_Point in some places of your code
#include "SDL.h"
#include <stdio.h>
int main(int argc, char *argv[]) {
SDL_Window *window;
// Position of window
SDL_Point window_position = {
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED
};640, 480}; // Size of window
SDL_Point window_size = {
// Mouse position coords
SDL_Point mouse_position;
// Initialize SDL2
SDL_Init(SDL_INIT_VIDEO);
// Create an application window with the following settings:
window = SDL_CreateWindow( "SDL_Point usage", // window title
// initial x position
window_position.x, // initial y position
window_position.y, // width, in pixels
window_size.x, // height, in pixels
window_size.y, // flags - see below
SDL_WINDOW_OPENGL
);
// Check that the window was successfully made
if (window == NULL) {
"Could not create window: %s", SDL_GetError());
SDL_Log(return 1;
}
// Sets mouse_position to...
SDL_GetMouseState( // ...mouse arrow coords on window
&mouse_position.x,
&mouse_position.y
);
"Mouse position: x=%i y=%i", // Print mouse position
SDL_Log(
mouse_position.x, mouse_position.y
);
// Close and destroy the window
SDL_DestroyWindow(window);
// Clean up
SDL_Quit();return 0;
}
An SDL_Point defines single two dimensional point. It can be used not only for points, but also for size. SDL_Point is used by SDL_GetRectEnclosingPoints() to check if array of points is inside rectangle (SDL_Rect). You can also make your own functions using SDL_Point to simplify your code, it's very helpful.