Add texture/color matrix sample

This commit is contained in:
UnknownShadow200 2025-02-22 10:52:09 +11:00
parent 2669a9266f
commit ff942e804e
6 changed files with 143 additions and 9 deletions

View File

@ -212,6 +212,7 @@ gen_sample(polymark samples/polymark/main.c)
gen_sample(cubes samples/cubes/main.cpp)
gen_sample(zclip_test tests/zclip/main.cpp)
gen_sample(primitive_modes samples/primitive_modes/main.c)
gen_sample(tnl_effects samples/tnl_effects/main.c)
if(PLATFORM_DREAMCAST)
gen_sample(trimark samples/trimark/main.c)

View File

@ -40,11 +40,11 @@ Matrix4x4* _glGetProjectionMatrix() {
}
Matrix4x4* _glGetTextureMatrix() {
return (Matrix4x4*) stack_top(&MATRIX_STACKS[2]);
return (Matrix4x4*) stack_top(MATRIX_STACKS + (GL_TEXTURE & 0xF));
}
Matrix4x4* _glGetColorMatrix() {
return (Matrix4x4*) stack_top(&MATRIX_STACKS[3]);
return (Matrix4x4*) stack_top(MATRIX_STACKS + (GL_COLOR & 0xF));
}
GLenum _glGetMatrixMode() {
@ -461,10 +461,6 @@ void gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx,
DownloadMatrix4x4(stack_top(MATRIX_STACKS + (GL_MODELVIEW & 0xF)));
}
void _glMatrixLoadTexture() {
UploadMatrix4x4((const Matrix4x4*) stack_top(MATRIX_STACKS + (GL_TEXTURE & 0xF)));
}
void _glMatrixLoadModelView() {
UploadMatrix4x4((const Matrix4x4*) stack_top(MATRIX_STACKS + (GL_MODELVIEW & 0xF)));
}

View File

@ -321,7 +321,6 @@ void _glInitSubmissionTarget();
void _glMatrixLoadNormal();
void _glMatrixLoadModelView();
void _glMatrixLoadProjection();
void _glMatrixLoadTexture();
void _glMatrixLoadModelViewProjection();
extern GLfloat DEPTH_RANGE_MULTIPLIER_L;

View File

@ -76,6 +76,7 @@ static void textureEffect(SubmissionTarget* target) {
Matrix4x4* m = _glGetTextureMatrix();
UploadMatrix4x4(m);
float coords[4];
float* ptr = (float*)m;
Vertex* it = _glSubmissionTargetStart(target);
uint32_t count = target->count;
@ -90,7 +91,7 @@ static void textureEffect(SubmissionTarget* target) {
void _glTnlUpdateTextureMatrix(void) {
Matrix4x4* m = _glGetTextureMatrix();
TNL_TEXTURE = _glIsIdentity(m);
TNL_TEXTURE = !_glIsIdentity(m);
updateEffects();
}
@ -115,7 +116,7 @@ static void colorEffect(SubmissionTarget* target) {
void _glTnlUpdateColorMatrix(void) {
Matrix4x4* m = _glGetColorMatrix();
TNL_COLOR = _glIsIdentity(m);
TNL_COLOR = !_glIsIdentity(m);
updateEffects();
}

View File

@ -69,10 +69,12 @@ __BEGIN_DECLS
#define GL_MODELVIEW 0x1700
#define GL_PROJECTION 0x1701
#define GL_TEXTURE 0x1702
#define GL_COLOR 0x1703 /* NOTE: Not the usual value */
#define GL_MODELVIEW_MATRIX 0x0BA6
#define GL_PROJECTION_MATRIX 0x0BA7
#define GL_TEXTURE_MATRIX 0x0BA8
#define GL_COLOR_MATRIX 0x80B1
/* Depth buffer */
#define GL_NEVER 0x0200

135
samples/tnl_effects/main.c Normal file
View File

@ -0,0 +1,135 @@
#include <GL/gl.h>
#include <math.h>
#include <stdlib.h>
#ifndef _arch_dreamcast
#include <SDL2/SDL.h>
static SDL_Window* win_handle;
#else
#include <kos.h>
#include <GL/glkos.h>
#endif
static void DrawQuad(float x, float y) {
glBegin(GL_QUADS);
x -= 1.0f;
y -= 1.0f;
glColor3f(0.5f, 0.5f, 0.5f); glTexCoord2f(0.0f, 0.0f); glVertex2f(x + 0.0f, y + 0.0f);
glColor3f(0.5f, 0.5f, 0.5f); glTexCoord2f(1.0f, 0.0f); glVertex2f(x + 0.3f, y + 0.0f);
glColor3f(0.5f, 0.5f, 0.5f); glTexCoord2f(1.0f, 1.0f); glVertex2f(x + 0.3f, y + 0.3f);
glColor3f(0.5f, 0.5f, 0.5f); glTexCoord2f(0.0f, 1.0f); glVertex2f(x + 0.0f, y + 0.3f);
glEnd();
}
static void sample_init() {
#ifdef SDL2_BUILD
SDL_Init(SDL_INIT_EVERYTHING);
win_handle = SDL_CreateWindow("Shapes", 0, 0, 640, 480, SDL_WINDOW_OPENGL);
SDL_GL_CreateContext(win_handle);
#else
glKosInit();
#endif
}
static int sample_should_exit() {
#ifndef _arch_dreamcast
SDL_Event event;
while (SDL_PollEvent(&event)) {
if(event.type == SDL_QUIT) return 1;
}
return 0;
#else
maple_device_t *cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);
if (!cont) return 0;
cont_state_t *state = (cont_state_t *)maple_dev_status(cont);
if (!state) return 0;
return state->buttons & CONT_START;
#endif
}
#define IMG_SIZE 8
int main(int argc, char *argv[]) {
sample_init();
glClearColor(0.2f, 0.2f, 0.2f, 1);
glViewport(0, 0, 640, 480);
glEnable(GL_TEXTURE_2D);
GLint tex;
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
static GLubyte texData[IMG_SIZE * IMG_SIZE * 4];
for (int y = 0, i = 0; y < IMG_SIZE; y++)
for (int x = 0; x < IMG_SIZE; x++, i += 4)
{
int a = x + y;
texData[i + 0] = (a & 1) ? 0xFF : 0;
texData[i + 1] = (a & 2) ? 0xFF : 0;
texData[i + 2] = (a & 4) ? 0xFF : 0;
texData[i + 3] = 0xFF;
}
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, IMG_SIZE, IMG_SIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
float time = 0.0f;
while (!sample_should_exit()) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
DrawQuad(0.1f, 0.1f);
glMatrixMode(GL_TEXTURE);
glTranslatef(time, 0, 0);
DrawQuad(0.5f, 0.1f);
glLoadIdentity();
glMatrixMode(GL_TEXTURE);
glTranslatef(0, time, 0);
DrawQuad(0.9f, 0.1f);
glLoadIdentity();
glMatrixMode(GL_TEXTURE);
glScalef(time, time * 0.5f, 0);
DrawQuad(1.3f, 0.1f);
glLoadIdentity();
glMatrixMode(GL_TEXTURE);
glRotatef(time * 1000, 1, 0, 0);
DrawQuad(1.7f, 0.1f);
glLoadIdentity();
glMatrixMode(GL_COLOR);
glTranslatef(time, 0, 0);
DrawQuad(0.1f, 0.5f);
glLoadIdentity();
glMatrixMode(GL_COLOR);
glTranslatef(0, time, 0);
DrawQuad(0.5f, 0.5f);
glLoadIdentity();
glMatrixMode(GL_COLOR);
glTranslatef(0, 0, time);
DrawQuad(0.9f, 0.5f);
glLoadIdentity();
glMatrixMode(GL_COLOR);
glScalef(time, time, time);
DrawQuad(1.3f, 0.5f);
glLoadIdentity();
glMatrixMode(GL_COLOR);
glRotatef(time * 1000, 1, 0, 0);
DrawQuad(0.1f, 0.5f);
glLoadIdentity();
#ifdef SDL2_BUILD
SDL_GL_SwapWindow(win_handle);
#else
glKosSwapBuffers();
#endif
time += 0.001f;
}
return 0;
}