本文整理汇总了C++中SDL_stack_alloc函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_stack_alloc函数的具体用法?C++ SDL_stack_alloc怎么用?C++ SDL_stack_alloc使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_stack_alloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WIN_CreateWindowFrom
int
WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
{
HWND hwnd = (HWND) data;
LPTSTR title;
int titleLen;
/* Query the title from the existing window */
titleLen = GetWindowTextLength(hwnd);
title = SDL_stack_alloc(TCHAR, titleLen + 1);
if (title) {
titleLen = GetWindowText(hwnd, title, titleLen);
} else {
titleLen = 0;
}
if (titleLen > 0) {
window->title = WIN_StringToUTF8(title);
}
if (title) {
SDL_stack_free(title);
}
if (SetupWindowData(_this, window, hwnd, SDL_FALSE) < 0) {
return -1;
}
return 0;
}
示例2: GLES_RenderDrawLines
static int
GLES_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
int count)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
int i;
GLshort *vertices;
GLES_SetBlendMode(data, renderer->blendMode, 1);
data->glColor4f((GLfloat) renderer->r * inv255f,
(GLfloat) renderer->g * inv255f,
(GLfloat) renderer->b * inv255f,
(GLfloat) renderer->a * inv255f);
vertices = SDL_stack_alloc(GLshort, count*2);
for (i = 0; i < count; ++i) {
vertices[2*i+0] = (GLshort)points[i].x;
vertices[2*i+1] = (GLshort)points[i].y;
}
data->glVertexPointer(2, GL_SHORT, 0, vertices);
data->glEnableClientState(GL_VERTEX_ARRAY);
if (count > 2 &&
points[0].x == points[count-1].x && points[0].y == points[count-1].y) {
/* GL_LINE_LOOP takes care of the final segment */
--count;
data->glDrawArrays(GL_LINE_LOOP, 0, count);
} else {
data->glDrawArrays(GL_LINE_STRIP, 0, count);
}
data->glDisableClientState(GL_VERTEX_ARRAY);
SDL_stack_free(vertices);
return 0;
}
示例3: GLES_RenderDrawPoints
static int
GLES_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
int count)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
int i;
GLshort *vertices;
GLES_SetBlendMode(data, renderer->blendMode, 1);
data->glColor4f((GLfloat) renderer->r * inv255f,
(GLfloat) renderer->g * inv255f,
(GLfloat) renderer->b * inv255f,
(GLfloat) renderer->a * inv255f);
vertices = SDL_stack_alloc(GLshort, count*2);
for (i = 0; i < count; ++i) {
vertices[2*i+0] = (GLshort)points[i].x;
vertices[2*i+1] = (GLshort)points[i].y;
}
data->glVertexPointer(2, GL_SHORT, 0, vertices);
data->glEnableClientState(GL_VERTEX_ARRAY);
data->glDrawArrays(GL_POINTS, 0, count);
data->glDisableClientState(GL_VERTEX_ARRAY);
SDL_stack_free(vertices);
return 0;
}
示例4: GLES_RenderDrawLines
static int
GLES_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
int count)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
int i;
GLshort *vertices;
GLES_SetDrawingState(renderer);
vertices = SDL_stack_alloc(GLshort, count*2);
for (i = 0; i < count; ++i) {
vertices[2*i+0] = (GLshort)points[i].x;
vertices[2*i+1] = (GLshort)points[i].y;
}
data->glVertexPointer(2, GL_SHORT, 0, vertices);
if (count > 2 &&
points[0].x == points[count-1].x && points[0].y == points[count-1].y) {
/* GL_LINE_LOOP takes care of the final segment */
--count;
data->glDrawArrays(GL_LINE_LOOP, 0, count);
} else {
data->glDrawArrays(GL_LINE_STRIP, 0, count);
/* We need to close the endpoint of the line */
data->glDrawArrays(GL_POINTS, count-1, 1);
}
SDL_stack_free(vertices);
return 0;
}
示例5: WIN_CreateWindowFrom
int
WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
{
HWND hwnd = (HWND) data;
LPTSTR title;
int titleLen;
/* Query the title from the existing window */
titleLen = GetWindowTextLength(hwnd);
title = SDL_stack_alloc(TCHAR, titleLen + 1);
if (title) {
titleLen = GetWindowText(hwnd, title, titleLen);
} else {
titleLen = 0;
}
if (titleLen > 0) {
window->title = WIN_StringToUTF8(title);
}
if (title) {
SDL_stack_free(title);
}
if (SetupWindowData(_this, window, hwnd, SDL_FALSE) < 0) {
return -1;
}
// Urho3D: if window will be used for OpenGL, choose pixel format
if (window->flags & SDL_WINDOW_OPENGL) {
if (WIN_GL_SetupWindow(_this, window) < 0) {
return -1;
}
}
return 0;
}
示例6: GLES_RenderDrawPoints
static int
GLES_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points,
int count)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
GLfloat *vertices;
int idx;
GLES_SetDrawingState(renderer);
/* Emit the specified vertices as points */
vertices = SDL_stack_alloc(GLfloat, count * 2);
for (idx = 0; idx < count; ++idx) {
GLfloat x = points[idx].x + 0.5f;
GLfloat y = points[idx].y + 0.5f;
vertices[idx * 2] = x;
vertices[(idx * 2) + 1] = y;
}
data->glVertexPointer(2, GL_FLOAT, 0, vertices);
data->glDrawArrays(GL_POINTS, 0, count);
SDL_stack_free(vertices);
return 0;
}
示例7: GLES_RenderDrawLines
static int
GLES_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points,
int count)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
GLfloat *vertices;
int idx;
GLES_SetDrawingState(renderer);
/* Emit a line strip including the specified vertices */
vertices = SDL_stack_alloc(GLfloat, count * 2);
for (idx = 0; idx < count; ++idx) {
GLfloat x = points[idx].x + 0.5f;
GLfloat y = points[idx].y + 0.5f;
vertices[idx * 2] = x;
vertices[(idx * 2) + 1] = y;
}
data->glVertexPointer(2, GL_FLOAT, 0, vertices);
if (count > 2 &&
points[0].x == points[count-1].x && points[0].y == points[count-1].y) {
/* GL_LINE_LOOP takes care of the final segment */
--count;
data->glDrawArrays(GL_LINE_LOOP, 0, count);
} else {
data->glDrawArrays(GL_LINE_STRIP, 0, count);
/* We need to close the endpoint of the line */
data->glDrawArrays(GL_POINTS, count-1, 1);
}
SDL_stack_free(vertices);
return 0;
}
示例8: WIN_CreateWindowFrom
int
WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
{
HWND hwnd = (HWND) data;
LPTSTR title;
int titleLen;
/* Query the title from the existing window */
titleLen = GetWindowTextLength(hwnd);
title = SDL_stack_alloc(TCHAR, titleLen + 1);
if (title) {
titleLen = GetWindowText(hwnd, title, titleLen);
} else {
titleLen = 0;
}
if (titleLen > 0) {
window->title = WIN_StringToUTF8(title);
}
if (title) {
SDL_stack_free(title);
}
if (SetupWindowData(_this, window, hwnd, SDL_FALSE) < 0) {
return -1;
}
// Urho3D: if window will be used for OpenGL, choose pixel format
if (window->flags & SDL_WINDOW_OPENGL) {
if (WIN_GL_SetupWindow(_this, window) < 0) {
return -1;
}
}
#if SDL_VIDEO_OPENGL_WGL
{
const char *hint = SDL_GetHint(SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT);
if (hint) {
// This hint is a pointer (in string form) of the address of
// the window to share a pixel format with
SDL_Window *otherWindow = NULL;
SDL_sscanf(hint, "%p", (void**)&otherWindow);
// Do some error checking on the pointer
if (otherWindow != NULL && otherWindow->magic == &_this->window_magic)
{
// If the otherWindow has SDL_WINDOW_OPENGL set, set it for the new window as well
if (otherWindow->flags & SDL_WINDOW_OPENGL)
{
window->flags |= SDL_WINDOW_OPENGL;
if(!WIN_GL_SetPixelFormatFrom(_this, otherWindow, window)) {
return -1;
}
}
}
}
}
#endif
return 0;
}
示例9: GL_RenderReadPixels
static int
GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 pixel_format, void * pixels, int pitch)
{
GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
SDL_Window *window = renderer->window;
Uint32 temp_format = SDL_PIXELFORMAT_ARGB8888;
void *temp_pixels;
int temp_pitch;
GLint internalFormat;
GLenum format, type;
Uint8 *src, *dst, *tmp;
int w, h, length, rows;
int status;
GL_ActivateRenderer(renderer);
temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format);
temp_pixels = SDL_malloc(rect->h * temp_pitch);
if (!temp_pixels) {
SDL_OutOfMemory();
return -1;
}
convert_format(data, temp_format, &internalFormat, &format, &type);
SDL_GetWindowSize(window, &w, &h);
data->glPixelStorei(GL_PACK_ALIGNMENT, 1);
data->glPixelStorei(GL_PACK_ROW_LENGTH,
(temp_pitch / SDL_BYTESPERPIXEL(temp_format)));
data->glReadPixels(rect->x, (h-rect->y)-rect->h, rect->w, rect->h,
format, type, temp_pixels);
/* Flip the rows to be top-down */
length = rect->w * SDL_BYTESPERPIXEL(temp_format);
src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch;
dst = (Uint8*)temp_pixels;
tmp = SDL_stack_alloc(Uint8, length);
rows = rect->h / 2;
while (rows--) {
SDL_memcpy(tmp, dst, length);
SDL_memcpy(dst, src, length);
SDL_memcpy(src, tmp, length);
dst += temp_pitch;
src -= temp_pitch;
}
SDL_stack_free(tmp);
status = SDL_ConvertPixels(rect->w, rect->h,
temp_format, temp_pixels, temp_pitch,
pixel_format, pixels, pitch);
SDL_free(temp_pixels);
return status;
}
示例10: WIN_SetWindowIcon
void
WIN_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
{
HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
HICON hicon = NULL;
BYTE *icon_bmp;
int icon_len;
SDL_RWops *dst;
SDL_Surface *surface;
/* Create temporary bitmap buffer */
icon_len = 40 + icon->h * icon->w * 4;
icon_bmp = SDL_stack_alloc(BYTE, icon_len);
dst = SDL_RWFromMem(icon_bmp, icon_len);
if (!dst) {
SDL_stack_free(icon_bmp);
return;
}
/* Write the BITMAPINFO header */
SDL_WriteLE32(dst, 40);
SDL_WriteLE32(dst, icon->w);
SDL_WriteLE32(dst, icon->h * 2);
SDL_WriteLE16(dst, 1);
SDL_WriteLE16(dst, 32);
SDL_WriteLE32(dst, BI_RGB);
SDL_WriteLE32(dst, icon->h * icon->w * 4);
SDL_WriteLE32(dst, 0);
SDL_WriteLE32(dst, 0);
SDL_WriteLE32(dst, 0);
SDL_WriteLE32(dst, 0);
/* Convert the icon to a 32-bit surface with alpha channel */
surface = SDL_ConvertSurfaceFormat(icon, SDL_PIXELFORMAT_ARGB8888, 0);
if (surface) {
/* Write the pixels upside down into the bitmap buffer */
int y = surface->h;
while (y--) {
Uint8 *src = (Uint8 *) surface->pixels + y * surface->pitch;
SDL_RWwrite(dst, src, surface->pitch, 1);
}
SDL_FreeSurface(surface);
/* TODO: create the icon in WinCE (CreateIconFromResource isn't available) */
#ifndef _WIN32_WCE
hicon = CreateIconFromResource(icon_bmp, icon_len, TRUE, 0x00030000);
#endif
}
SDL_RWclose(dst);
SDL_stack_free(icon_bmp);
/* Set the icon for the window */
SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
/* Set the icon in the task manager (should we do this?) */
SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
}
示例11: D3D_RenderDrawLines
static int
D3D_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
int count)
{
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
DWORD color;
Vertex *vertices;
int i;
HRESULT result;
if (data->beginScene) {
IDirect3DDevice9_BeginScene(data->device);
data->beginScene = SDL_FALSE;
}
D3D_SetBlendMode(data, renderer->blendMode);
result =
IDirect3DDevice9_SetTexture(data->device, 0,
(IDirect3DBaseTexture9 *) 0);
if (FAILED(result)) {
D3D_SetError("SetTexture()", result);
return -1;
}
color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);
vertices = SDL_stack_alloc(Vertex, count);
for (i = 0; i < count; ++i) {
vertices[i].x = (float) points[i].x;
vertices[i].y = (float) points[i].y;
vertices[i].z = 0.0f;
vertices[i].rhw = 1.0f;
vertices[i].color = color;
vertices[i].u = 0.0f;
vertices[i].v = 0.0f;
}
result =
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_LINESTRIP, count-1,
vertices, sizeof(*vertices));
/* DirectX 9 has the same line rasterization semantics as GDI,
so we need to close the endpoint of the line */
if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
vertices[0].x = (float) points[count-1].x;
vertices[0].y = (float) points[count-1].y;
result = IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_POINTLIST, 1, vertices, sizeof(*vertices));
}
SDL_stack_free(vertices);
if (FAILED(result)) {
D3D_SetError("DrawPrimitiveUP()", result);
return -1;
}
return 0;
}
示例12: GDI_RenderDrawLines
static int
GDI_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
int count)
{
GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
HPEN pen;
BOOL status;
if (data->makedirty) {
/* Get the smallest rectangle that contains everything */
SDL_Window *window = renderer->window;
SDL_Rect clip, rect;
clip.x = 0;
clip.y = 0;
clip.w = window->w;
clip.h = window->h;
SDL_EnclosePoints(points, count, NULL, &rect);
if (!SDL_IntersectRect(&rect, &clip, &rect)) {
/* Nothing to draw */
return 0;
}
SDL_AddDirtyRect(&data->dirty, &rect);
}
/* Should we cache the pen? .. it looks like GDI does for us. :) */
pen = CreatePen(PS_SOLID, 1, RGB(renderer->r, renderer->g, renderer->b));
SelectObject(data->current_hdc, pen);
{
LPPOINT p = SDL_stack_alloc(POINT, count);
int i;
for (i = 0; i < count; ++i) {
p[i].x = points[i].x;
p[i].y = points[i].y;
}
status = Polyline(data->current_hdc, p, count);
SDL_stack_free(p);
}
DeleteObject(pen);
/* Need to close the endpoint of the line */
if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
SetPixel(data->current_hdc, points[count-1].x, points[count-1].y,
RGB(renderer->r, renderer->g, renderer->b));
}
if (!status) {
WIN_SetError("Polyline()");
return -1;
}
return 0;
}
示例13: GLES_RenderReadPixels
static int
GLES_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 pixel_format, void * pixels, int pitch)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
Uint32 temp_format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ABGR8888;
void *temp_pixels;
int temp_pitch;
Uint8 *src, *dst, *tmp;
int w, h, length, rows;
int status;
GLES_ActivateRenderer(renderer);
temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format);
temp_pixels = SDL_malloc(rect->h * temp_pitch);
if (!temp_pixels) {
return SDL_OutOfMemory();
}
SDL_GetRendererOutputSize(renderer, &w, &h);
data->glPixelStorei(GL_PACK_ALIGNMENT, 1);
data->glReadPixels(rect->x, renderer->target ? rect->y : (h-rect->y)-rect->h,
rect->w, rect->h, GL_RGBA, GL_UNSIGNED_BYTE, temp_pixels);
/* Flip the rows to be top-down if necessary */
if (!renderer->target) {
length = rect->w * SDL_BYTESPERPIXEL(temp_format);
src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch;
dst = (Uint8*)temp_pixels;
tmp = SDL_stack_alloc(Uint8, length);
rows = rect->h / 2;
while (rows--) {
SDL_memcpy(tmp, dst, length);
SDL_memcpy(dst, src, length);
SDL_memcpy(src, tmp, length);
dst += temp_pitch;
src -= temp_pitch;
}
SDL_stack_free(tmp);
}
status = SDL_ConvertPixels(rect->w, rect->h,
temp_format, temp_pixels, temp_pitch,
pixel_format, pixels, pitch);
SDL_free(temp_pixels);
return status;
}
示例14: X11_RenderDrawPoints
static int
X11_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
int count)
{
X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
SDL_Window *window = renderer->window;
unsigned long foreground;
XPoint *xpoints, *xpoint;
int i, xcount;
if (data->makedirty) {
SDL_Rect rect;
/* Get the smallest rectangle that contains everything */
rect.x = 0;
rect.y = 0;
rect.w = window->w;
rect.h = window->h;
if (!SDL_EnclosePoints(points, count, &rect, &rect)) {
/* Nothing to draw */
return 0;
}
SDL_AddDirtyRect(&data->dirty, &rect);
}
foreground = renderdrawcolor(renderer, 1);
XSetForeground(data->display, data->gc, foreground);
xpoint = xpoints = SDL_stack_alloc(XPoint, count);
xcount = 0;
for (i = 0; i < count; ++i) {
int x = points[i].x;
int y = points[i].y;
if (x < 0 || x >= window->w || y < 0 || y >= window->h) {
continue;
}
xpoint->x = (short)x;
xpoint->y = (short)y;
++xpoint;
++xcount;
}
if (xcount > 0) {
XDrawPoints(data->display, data->drawable, data->gc, xpoints, xcount,
CoordModeOrigin);
}
SDL_stack_free(xpoints);
return 0;
}
示例15: SW_RenderFillRects
static int
SW_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, int count)
{
SDL_Surface *surface = SW_ActivateRenderer(renderer);
SDL_Rect *final_rects;
int i, status;
if (!surface) {
return -1;
}
final_rects = SDL_stack_alloc(SDL_Rect, count);
if (!final_rects) {
return SDL_OutOfMemory();
}
if (renderer->viewport.x || renderer->viewport.y) {
int x = renderer->viewport.x;
int y = renderer->viewport.y;
for (i = 0; i < count; ++i) {
final_rects[i].x = (int)(x + rects[i].x);
final_rects[i].y = (int)(y + rects[i].y);
final_rects[i].w = SDL_max((int)rects[i].w, 1);
final_rects[i].h = SDL_max((int)rects[i].h, 1);
}
} else {
for (i = 0; i < count; ++i) {
final_rects[i].x = (int)rects[i].x;
final_rects[i].y = (int)rects[i].y;
final_rects[i].w = SDL_max((int)rects[i].w, 1);
final_rects[i].h = SDL_max((int)rects[i].h, 1);
}
}
if (renderer->blendMode == SDL_BLENDMODE_NONE) {
Uint32 color = SDL_MapRGBA(surface->format,
renderer->r, renderer->g, renderer->b,
renderer->a);
status = SDL_FillRects(surface, final_rects, count, color);
} else {
status = SDL_BlendFillRects(surface, final_rects, count,
renderer->blendMode,
renderer->r, renderer->g, renderer->b,
renderer->a);
}
SDL_stack_free(final_rects);
return status;
}