|
Size: 2185
Comment: Grammar
|
Size: 2443
Comment: Changed code example to be more compatible C and replaced tabs.
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 21: | Line 21: |
| int main(int argc, char *argv[]){ | int main(int argc, char *argv[]) { |
| Line 23: | Line 23: |
| SDL_Init(SDL_INIT_VIDEO); // Initialize SDL2 | SDL_Window *window; |
| Line 25: | Line 25: |
| SDL_Point window_position = { // Position of window | SDL_Point window_position = { // Position of window |
| Line 28: | Line 28: |
| }; SDL_Point window_size = {640, 480}; // Size of window |
}; SDL_Point window_size = {640, 480}; // Size of window |
| Line 31: | Line 31: |
| SDL_Point mouse_position; // Mouse position coord's | SDL_Point mouse_position; // Mouse position coords |
| Line 33: | Line 33: |
| // Create an application window with the following settings: SDL_Window *window = SDL_CreateWindow( "SDL_Point usage", // window title window_position.x, // initial x position window_position.y, // initial y position window_size.x, // width, in pixels window_size.y, // height, in pixels SDL_WINDOW_OPENGL // flags - see below ); |
SDL_Init(SDL_INIT_VIDEO); // Initialize SDL2 |
| Line 43: | Line 35: |
| // Check that the window was successfully made if(window == NULL){ printf("Could not create window: %s\n", SDL_GetError()); return 1; } |
// Create an application window with the following settings: window = SDL_CreateWindow( "SDL_Point usage", // window title window_position.x, // initial x position window_position.y, // initial y position window_size.x, // width, in pixels window_size.y, // height, in pixels SDL_WINDOW_OPENGL // flags - see below ); |
| Line 49: | Line 45: |
| SDL_GetMouseState( // Sets mouse_position to... &mouse_position.x, // ...mouse arrow coord's on window |
// Check that the window was successfully made if (window == NULL) { printf("Could not create window: %s\n", SDL_GetError()); return 1; } SDL_GetMouseState( // Sets mouse_position to... &mouse_position.x, // ...mouse arrow coords on window |
| Line 52: | Line 54: |
| ); | ); |
| Line 54: | Line 56: |
| printf("Mouse position: x=%i y=%i\n", // Print mouse position | printf("Mouse position: x=%i y=%i\n", // Print mouse position |
| Line 56: | Line 58: |
| ); | ); |
| Line 58: | Line 60: |
| // Close and destroy the window SDL_DestroyWindow(window); |
// Close and destroy the window SDL_DestroyWindow(window); |
| Line 61: | Line 63: |
| // Clean up SDL_Quit(); return 0; |
// Clean up SDL_Quit(); return 0; |
SDL_Point
A structure that defines a two dimensional point.
Data Fields
int |
x |
the x coordinate of the point |
int |
y |
the y coordinate of the point |
Code Examples
// 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;
SDL_Point window_position = { // Position of window
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED
};
SDL_Point window_size = {640, 480}; // Size of window
SDL_Point mouse_position; // Mouse position coords
SDL_Init(SDL_INIT_VIDEO); // Initialize SDL2
// Create an application window with the following settings:
window = SDL_CreateWindow(
"SDL_Point usage", // window title
window_position.x, // initial x position
window_position.y, // initial y position
window_size.x, // width, in pixels
window_size.y, // height, in pixels
SDL_WINDOW_OPENGL // flags - see below
);
// Check that the window was successfully made
if (window == NULL) {
printf("Could not create window: %s\n", SDL_GetError());
return 1;
}
SDL_GetMouseState( // Sets mouse_position to...
&mouse_position.x, // ...mouse arrow coords on window
&mouse_position.y
);
printf("Mouse position: x=%i y=%i\n", // Print mouse position
mouse_position.x, mouse_position.y
);
// Close and destroy the window
SDL_DestroyWindow(window);
// Clean up
SDL_Quit();
return 0;
}
Remarks
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_EnclosePoints() 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.
Related Structures
