Commit graph

845 commits

Author SHA1 Message Date
Clownacy
d8aec418f9 OpenGL: Use a struct for defining 2D coordinates
Makes the code a bit more readable
2019-08-01 13:11:55 +00:00
Clownacy
67b3143ed6 OpenGL: Only enable blending for glyphs
Should improve performance
2019-08-01 01:26:04 +00:00
Clownacy
cf94736cbf OpenGL: Free VAO and VBO 2019-08-01 00:38:23 +00:00
Clownacy
d8d971c459 Added another bugfix 2019-08-01 00:34:35 +00:00
Clownacy
f0c062cdc8 OpenGL: Clamp textures
This fixes this weird thing you'd see in the enhanced branch if the
screen is scaled (happens if you resize the window).

When the screen is scaled, OpenGL uses linear interpolation. This
would cause it to fetch samples from outside the texture. IIRC, by
default, the default behaviour is GL_REPEAT, which causes it to blend
with samples from the other side of the texture, creating strange
pixels at the end of the screen.
2019-08-01 00:08:23 +00:00
Clownacy
706aff0c8c Remove more redundant OpenGL code 2019-07-31 23:43:08 +00:00
Clownacy
607bbfcef8 Remove some debug prints
I prefer to only print on error
2019-07-31 23:12:06 +00:00
Clownacy
90ffbacd29 Put OpenGL in 'forward-compatible' mode
Disables deprecated functionality
2019-07-31 23:07:45 +00:00
Clownacy
4769397c7a Clean up OpenGL error callback print 2019-07-31 23:03:32 +00:00
Clownacy
24dcd35522 More OpenGL cleanup and tweaks 2019-07-31 23:01:14 +00:00
Clownacy
ff5a0189e0 OpenGL: Ditch index buffer
Seems completely unnecessary for 2D
2019-07-31 22:50:14 +00:00
Clownacy
350ba46f2e Some OpenGL cleanup 2019-07-31 22:48:37 +00:00
Clownacy
eb62a80956 Change references to OpenGL 2.1 to 3.2 2019-07-31 22:38:33 +00:00
Clownacy
4c024b540f Migrated OpenGL backend to OpenGL 3.2
Goddammit 3.2 is so complex.

The reason I want 3.2 is because I'm not convinced Legacy OpenGL will
be well-supported in the future. 3.2 is about as far back as I can go
without breaking forward-compatibility (it was the first version to
introduce the Core Profile).
2019-07-31 22:33:22 +00:00
Clownacy
2c9531062b Move away from Legacy OpenGL shader variables 2019-07-31 21:00:07 +00:00
Clownacy
e447c9fb92 Missed some matrix code 2019-07-31 06:36:13 +00:00
Clownacy
74c29dbe3c Disable texture coordinates entirely when colour-filling 2019-07-31 06:35:32 +00:00
Clownacy
106827c2ee No more Legacy OpenGL ModelView matrix
I'd replace it with a custom matrix, but I get the feeling the
overhead of uploading a 4x4 matrix every quad is higher than just
manipulating the vertexes CPU-side
2019-07-31 05:49:39 +00:00
Clownacy
bd731321f2 Use triangle fans instead of quads
Quads are Legacy OpenGL
2019-07-31 04:54:22 +00:00
Clownacy
eab2a80ae5 Remove some vestigal matrix code 2019-07-31 04:52:31 +00:00
Clownacy
42765792bc Shut up some warnings 2019-07-31 04:41:46 +00:00
Clownacy
3973419cef Fix Makefile when building SDLSurface backend 2019-07-31 03:51:18 +00:00
Clownacy
a5fd0cebc0 Use specialised shaders for everything
Saves us having to do a bunch of extra legwork (setting up the blank
default texture, setting the colour modifier to white, etc.), and
should improve performance.

While I was at it, I made the colour modifier a uniform, so it only
has to be set once per quad, rather than once per vertex.
2019-07-31 03:39:30 +00:00
Clownacy
d9929a8e1f This shouldn't be needed anymore 2019-07-31 03:04:32 +00:00
Clownacy
92476bd30a Made the OpenGL 2.1 backend use custom shaders
Edging towards OpenGL 3.
2019-07-31 03:00:56 +00:00
Clownacy
f0809fb901 Change colour_buffer assignments 2019-07-31 02:57:11 +00:00
Clownacy
9cc1a5a098 Change colour_buffer to unsigned bytes instead of floats 2019-07-31 02:55:22 +00:00
Clownacy
64f7a2eae3 Use GL_LUMINANCE_ALPHA instead of GL_ALPHA
GL_ALPHA sets the RGB values to 0.0, but I want them set to 1.0
2019-07-31 02:52:43 +00:00
Clownacy
348a691c6c GLU is unneeded 2019-07-31 02:49:07 +00:00
Clownacy
03b33adb70 Switch OpenGL 2.1 backend to use vertex arrays
This replaces the glBegin/glEnd stuff. Even though vertex arrays
aren't removed from newer OpenGL versions like glBegin/glEnd are,
they *are* deprecated, so I want to switch to VBOs eventually.
2019-07-29 18:11:46 +00:00
Clownacy
0b874153d4 Free the string returned by SDL_GetBasePath
Thanks, Fayti1703.
2019-07-29 14:33:14 +00:00
Clownacy
2d73fd8bb9 Use GLEW to check if OpenGL 2.1 is supported 2019-07-27 03:42:51 +00:00
Clownacy
0abac07aab Note the new dependency on GLEW
I wonder if I could use SDL2's SDL_GL_GetProcAddress,
SDL_GL_ExtensionSupported, and SDL_GL_LoadLibrary functions to bypass
needing GLEW? Then again, I'd like to remove the dependency on SDL2
at some point as well...
2019-07-27 03:36:35 +00:00
Clownacy
aa728979a3 Fix the Texture backend not rendering text the accurate buggy way
A shame I have to fall back on the Surface fallback. Speaking of, I
really need to replace that fallback with my software renderer.
2019-07-25 00:39:03 +01:00
Clownacy
defe234ff2 Clean up some ugly formatting 2019-07-25 00:09:10 +01:00
Clownacy
145864cf2d Added sanity checks to the backends
This fixes the Texture backend bug that made the program take forever
to shut down:

The problem was that the font system would try to load a glyph that's
0 pixels wide/tall (likely the space character), which SDL2 didn't
like, so it would fail to allocate the texture, causing
Backend_CreateSurface, and by extension Backend_CreateGlyph, to
return a NULL. Later, upon shutdown, the font system would pass this
NULL to Backend_FreeGlyph, causing NULL pointer dereferences that
make the program take forever to shut down.

Personally, I think passing NULLs to the backend is valid behaviour,
so I've added a bunch of sanity checks to make sure they're never
dereferenced.
2019-07-24 23:34:16 +01:00
Clownacy
679c6d0391 More efficient OpenGL font loading 2019-07-24 22:21:39 +01:00
Clownacy
d6888040a2 Backport some OpenGL 2.1 fixes 2019-07-24 22:08:37 +01:00
Clownacy
9948fa8b07 Move the SDL_Window creation to the rendering backends
Whoops, didn't mean to commit the Main.cpp edit way back when I made
the OpenGL 2.1 backend.
2019-07-24 20:20:06 +01:00
Clownacy
b998719ff1 Update CMakeLists.txt, the Makefile, and the readme 2019-07-24 20:09:27 +01:00
Clownacy
7bbc0321cd Backport OpenGL2 fixes from the enhanced branch 2019-07-24 20:00:50 +01:00
Clownacy
b2244f17fc Dumb indent 2019-07-23 23:15:44 +01:00
Clownacy
0ce05e1837 Move a function 2019-07-23 23:13:57 +01:00
Clownacy
e170485849 Document a "bug" in the SDL_Texture backend 2019-07-23 23:11:24 +01:00
Clownacy
d3129bc4bc Font refactor part 5: Sigil (optimised software renderer) 2019-07-23 21:49:40 +01:00
Clownacy
8aad8a6628 Font refactor part 4: Thy Flesh Co- I mean, OpenGL
Hard mode. Wound up debugging a weird issue for about half an hour.
Turns out you don't need to reset the matrix when you switch
framebuffer target? I don't really know how that works.

Anyway, yay font rendering is in the OpenGL backend now.
2019-07-23 21:49:40 +01:00
Clownacy
e2054918a6 Font refactor part 3: SDL_Texture
Getting kinda messy, having to maintain two different ways of
drawing - colour-key and alpha-blending. In the enhanced branch,
which uses alpha-blending for everything, these can be merged.

I'm noticing a huge delay in shutdown time. There's probably a bug
in here.
2019-07-23 21:49:40 +01:00
Clownacy
6a7fd14833 Font refactor part 2: SDL_Surface
No per-component alpha support here
2019-07-23 17:20:56 +01:00
Clownacy
6d385e674f Font refactor part 1: Software
With this, font blitting is handled by the rendering backend, paving
the way for hardware-accelerated font drawing in the accelerated
backends.
2019-07-23 16:38:04 +01:00
Clownacy
90f29377fe Apply some surface ID constants 2019-07-23 15:20:13 +01:00