31#define _Class _Renderer
33#pragma mark - Renderer
42 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
44 glEnable(GL_SCISSOR_TEST);
46 glEnableClientState(GL_VERTEX_ARRAY);
47 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
61 switch (surface->format->BytesPerPixel) {
63 format = GL_LUMINANCE;
72 MVC_LogError(
"Invalid surface format: %s\n", SDL_GetPixelFormatName(surface->format->format));
77 glGenTextures(1, &texture);
79 glBindTexture(GL_TEXTURE_2D, texture);
81 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
82 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
83 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE);
85 glTexImage2D(GL_TEXTURE_2D, 0, format, surface->w, surface->h, 0, format, GL_UNSIGNED_BYTE, surface->pixels);
109 glVertexPointer(2, GL_INT, 0, points);
111 glDrawArrays(GL_LINE_STRIP, 0, (GLsizei) count);
127 verts[2] = rect->x + rect->w;
130 verts[4] = rect->x + rect->w;
131 verts[5] = rect->y + rect->h;
134 verts[7] = rect->y + rect->h;
136 glVertexPointer(2, GL_INT, 0, verts);
137 glDrawArrays(GL_LINE_LOOP, 0, 4);
148 glRecti(rect->x - 1, rect->y - 1, rect->x + rect->w + 1, rect->y + rect->h + 1);
159 const GLfloat texcoords[] = {
171 verts[2] = rect->x + rect->w;
174 verts[4] = rect->x + rect->w;
175 verts[5] = rect->y + rect->h;
178 verts[7] = rect->y + rect->h;
180 glEnable(GL_TEXTURE_2D);
181 glBindTexture(GL_TEXTURE_2D, texture);
183 glVertexPointer(2, GL_INT, 0, verts);
184 glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
186 glDrawArrays(GL_QUADS, 0, 4);
188 glDisable(GL_TEXTURE_2D);
216 glDisableClientState(GL_VERTEX_ARRAY);
217 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
221 glDisable(GL_SCISSOR_TEST);
223 glBlendFunc(GL_ONE, GL_ZERO);
226 const GLenum err = glGetError();
262 SDL_Window *window = SDL_GL_GetCurrentWindow();
269 SDL_GL_GetDrawableSize(window, &rect.w, &rect.h);
274 glScissor(scissor.x - 1, scissor.y - 1, scissor.w + 2, scissor.h + 2);
282 glColor4ubv((
const GLubyte *) color);
285#pragma mark - Class lifecycle
292 ((RendererInterface *) clazz->interface)->beginFrame =
beginFrame;
293 ((RendererInterface *) clazz->interface)->createTexture =
createTexture;
294 ((RendererInterface *) clazz->interface)->drawLine =
drawLine;
295 ((RendererInterface *) clazz->interface)->drawLines =
drawLines;
296 ((RendererInterface *) clazz->interface)->drawRect =
drawRect;
297 ((RendererInterface *) clazz->interface)->drawRectFilled =
drawRectFilled;
298 ((RendererInterface *) clazz->interface)->drawTexture =
drawTexture;
299 ((RendererInterface *) clazz->interface)->drawView =
drawView;
300 ((RendererInterface *) clazz->interface)->endFrame =
endFrame;
301 ((RendererInterface *) clazz->interface)->init =
init;
304 ((RendererInterface *) clazz->interface)->setClippingFrame =
setClippingFrame;
305 ((RendererInterface *) clazz->interface)->setDrawColor =
setDrawColor;
317 clazz = _initialize(&(
const ClassDef) {
319 .superclass = _Object(),
321 .interfaceOffset = offsetof(
Renderer, interface),
322 .interfaceSize =
sizeof(RendererInterface),
View logging facilities via SDL_Log.
#define MVC_LogError(fmt,...)
static void initialize(Class *clazz)
The Renderer is responsible for rasterizing the View hierarchy of a WindowController.
#define MakeRect(x, y, w, h)
Creates an SDL_Rect with the given origin and size.
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
SDL_Rect MVC_TransformToWindow(SDL_Window *window, const SDL_Rect *rect)
Transforms the specified rectangle to normalized device coordinates in window.
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.
void renderDeviceDidReset(Font *self)
This method should be invoked when the render context is invalidated.
The Renderer is responsible for rasterizing the View hierarchy of a WindowController.
void setClippingFrame(Renderer *self, const SDL_Rect *clippingFrame)
Sets the clipping frame for draw operations.
GLuint createTexture(const Renderer *self, const SDL_Surface *surface)
Generates and binds to an OpenGL texture object, uploading the given surface.
void endFrame(Renderer *self)
void drawRectFilled(const Renderer *self, const SDL_Rect *rect)
Fills a rectangle using glRecti.
void drawRect(const Renderer *self, const SDL_Rect *rect)
Draws a rectangle using GL_LINE_LOOP.
Class * _Renderer(void)
The Renderer archetype.
void renderDeviceWillReset(Renderer *self)
This method is invoked when the render device will become reset.
void drawLines(const Renderer *self, const SDL_Point *points, size_t count)
Draws line segments between adjacent points using GL_LINE_STRIP.
void drawLine(const Renderer *self, const SDL_Point *points)
Draws a line segment between two points using GL_LINE_STRIP.
void drawTexture(const Renderer *self, GLuint texture, const SDL_Rect *dest)
Draws a textured GL_QUAD in the given rectangle.
void drawView(Renderer *self, View *view)
Draws the given View, setting the clipping frame and invoking View::render.
void setDrawColor(Renderer *self, const SDL_Color *color)
Sets the primary color for drawing operations.
void beginFrame(Renderer *self)
Sets up OpenGL state.
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
SDL_Rect clippingFrame(const View *self)
void renderDeviceDidReset(View *self)
Informs this View that the render device has reset.
void render(View *self, Renderer *renderer)
Renders this View using the given renderer.