Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raster: implement glPixelZoom #75

Merged
merged 1 commit into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ static const ProcMap s_proc_map[] = {
PROC(glPixelStorei),
//PROC(glPixelTransferf),
//PROC(glPixelTransferi),
//PROC(glPixelZoom),
PROC(glPixelZoom),
PROC(glPointSize),
PROC(glPolygonMode),
PROC(glPolygonOffset),
Expand Down
2 changes: 2 additions & 0 deletions src/gc_gl.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ void ogx_initialize()
glparamstate.raster_pos[2] = 0.0f;
glparamstate.raster_pos[3] = 1.0f;
glparamstate.raster_pos_valid = true;
glparamstate.pixel_zoom_x = 1.0f;
glparamstate.pixel_zoom_y = 1.0f;

glparamstate.depth_near = 0.0f;
glparamstate.depth_far = 1.0f;
Expand Down
6 changes: 6 additions & 0 deletions src/getters.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@ void glGetIntegerv(GLenum pname, GLint *params)
case GL_RENDER_MODE:
*params = glparamstate.render_mode;
return;
case GL_ZOOM_X:
*params = glparamstate.pixel_zoom_x;
break;
case GL_ZOOM_Y:
*params = glparamstate.pixel_zoom_y;
break;
default:
return;
};
Expand Down
14 changes: 10 additions & 4 deletions src/raster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ POSSIBILITY OF SUCH DAMAGE.
#include <malloc.h>
#include <type_traits>

void glPixelZoom(GLfloat xfactor, GLfloat yfactor)
{
glparamstate.pixel_zoom_x = xfactor;
glparamstate.pixel_zoom_y = yfactor;
}

static void set_current_raster_pos(const guVector *pos)
{
guVector pos_mv;
Expand Down Expand Up @@ -226,22 +232,22 @@ static void draw_raster_texture(GXTexObj *texture, int width, int height,

int y0, y1;
if (height < 0) {
y0 = screen_y + height;
y0 = screen_y + height * glparamstate.pixel_zoom_y;
y1 = screen_y;
} else {
/* The first row we read from the bitmap is the bottom row, so let's take
* this into account and flip the image vertically */
y0 = screen_y;
y1 = screen_y - height;
y1 = screen_y - height * glparamstate.pixel_zoom_y;
}
GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
GX_Position3f32(screen_x, y0, screen_z);
GX_TexCoord2u8(0, 0);
GX_Position3f32(screen_x, y1, screen_z);
GX_TexCoord2u8(0, 1);
GX_Position3f32(screen_x + width, y1, screen_z);
GX_Position3f32(screen_x + width * glparamstate.pixel_zoom_x, y1, screen_z);
GX_TexCoord2u8(1, 1);
GX_Position3f32(screen_x + width, y0, screen_z);
GX_Position3f32(screen_x + width * glparamstate.pixel_zoom_x, y0, screen_z);
GX_TexCoord2u8(1, 0);
GX_End();
}
Expand Down
2 changes: 2 additions & 0 deletions src/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ typedef struct glparams_
float texture_object_plane_s[4];
float texture_object_plane_t[4];
float raster_pos[4];
float pixel_zoom_x;
float pixel_zoom_y;
float depth_near;
float depth_far;
int cur_modv_mat, cur_proj_mat;
Expand Down