mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-02-08 23:20:12 +00:00
more changes to make Rug work on Android
This commit is contained in:
parent
bd84b76c1b
commit
0a7c07fa7d
@ -332,6 +332,14 @@ void setGLProjection(int col) {
|
|||||||
stereo::set_projection(0);
|
stereo::set_projection(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline int next_p2 (int a )
|
||||||
|
{
|
||||||
|
int rval=1;
|
||||||
|
// rval<<=1 Is A Prettier Way Of Writing rval*=2;
|
||||||
|
while(rval<a) rval<<=1;
|
||||||
|
return rval;
|
||||||
|
}
|
||||||
|
|
||||||
#if CAP_GLFONT
|
#if CAP_GLFONT
|
||||||
|
|
||||||
struct glfont_t {
|
struct glfont_t {
|
||||||
@ -345,14 +353,6 @@ struct glfont_t {
|
|||||||
|
|
||||||
glfont_t *glfont[256];
|
glfont_t *glfont[256];
|
||||||
|
|
||||||
inline int next_p2 (int a )
|
|
||||||
{
|
|
||||||
int rval=1;
|
|
||||||
// rval<<=1 Is A Prettier Way Of Writing rval*=2;
|
|
||||||
while(rval<a) rval<<=1;
|
|
||||||
return rval;
|
|
||||||
}
|
|
||||||
|
|
||||||
void glError(const char* GLcall, const char* file, const int line) {
|
void glError(const char* GLcall, const char* file, const int line) {
|
||||||
GLenum errCode = glGetError();
|
GLenum errCode = glGetError();
|
||||||
if(errCode!=GL_NO_ERROR) {
|
if(errCode!=GL_NO_ERROR) {
|
||||||
|
3
init.cpp
3
init.cpp
@ -301,6 +301,7 @@ void gdpush(int t);
|
|||||||
#define SDLK_KP_ENTER (123054)
|
#define SDLK_KP_ENTER (123054)
|
||||||
#define SDLK_BACKSPACE (123055)
|
#define SDLK_BACKSPACE (123055)
|
||||||
typedef int SDL_Event;
|
typedef int SDL_Event;
|
||||||
|
typedef unsigned int Uint32;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ISWEB
|
#if ISWEB
|
||||||
@ -330,6 +331,8 @@ inline Uint8 *SDL_GetKeyState(void *v) { static Uint8 tab[1024]; return tab; }
|
|||||||
#include <GLES/gl.h>
|
#include <GLES/gl.h>
|
||||||
#include <GLES/glext.h>
|
#include <GLES/glext.h>
|
||||||
#include <GLES2/gl2.h>
|
#include <GLES2/gl2.h>
|
||||||
|
#include <GLES3/gl3.h>
|
||||||
|
#define GLES_ONLY
|
||||||
#else
|
#else
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <GL/glu.h>
|
#include <GL/glu.h>
|
||||||
|
@ -40,7 +40,6 @@ renderbuffer::renderbuffer(int x, int y, bool gl) : x(x), y(y) {
|
|||||||
if(gl) {
|
if(gl) {
|
||||||
tx = next_p2(x);
|
tx = next_p2(x);
|
||||||
ty = next_p2(y);
|
ty = next_p2(y);
|
||||||
s = NULL;
|
|
||||||
#if CAP_GLEW
|
#if CAP_GLEW
|
||||||
if(!glew) {
|
if(!glew) {
|
||||||
glew = true;
|
glew = true;
|
||||||
@ -53,7 +52,7 @@ renderbuffer::renderbuffer(int x, int y, bool gl) : x(x), y(y) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
FramebufferName = renderedTexture = depth_stencil_rb = 0;
|
FramebufferName = renderedTexture = depth_stencil_rb = 0;
|
||||||
glGenFramebuffers(1, &FramebufferName);
|
glGenFramebuffers(1, &FramebufferName); //
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
|
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
|
||||||
|
|
||||||
glGenTextures(1, &renderedTexture);
|
glGenTextures(1, &renderedTexture);
|
||||||
@ -67,8 +66,8 @@ renderbuffer::renderbuffer(int x, int y, bool gl) : x(x), y(y) {
|
|||||||
#else
|
#else
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, renderedTexture, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, renderedTexture, 0);
|
||||||
#endif
|
#endif
|
||||||
GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
|
// GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
|
||||||
glDrawBuffers(1, DrawBuffers);
|
// glDrawBuffers(1, DrawBuffers);
|
||||||
|
|
||||||
glGenRenderbuffers(1, &depth_stencil_rb);
|
glGenRenderbuffers(1, &depth_stencil_rb);
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, depth_stencil_rb);
|
glBindRenderbuffer(GL_RENDERBUFFER, depth_stencil_rb);
|
||||||
@ -96,7 +95,7 @@ void renderbuffer::make_surface() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SDL_Surface *renderbuffer::render() {
|
SDL_Surface *renderbuffer::render() {
|
||||||
make_surface();
|
make_surface() ;
|
||||||
if(FramebufferName) {
|
if(FramebufferName) {
|
||||||
glReadPixels(0, 0, vid.xres, vid.yres, GL_BGRA, GL_UNSIGNED_BYTE, srf->pixels);
|
glReadPixels(0, 0, vid.xres, vid.yres, GL_BGRA, GL_UNSIGNED_BYTE, srf->pixels);
|
||||||
for(int y=0; y<vid.yres/2; y++)
|
for(int y=0; y<vid.yres/2; y++)
|
||||||
@ -127,7 +126,9 @@ void renderbuffer::disable() {
|
|||||||
#if CAP_GL
|
#if CAP_GL
|
||||||
if(FramebufferName) {
|
if(FramebufferName) {
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
#if CAP_SDL
|
||||||
glViewport(0,0,s_screen->w,s_screen->h);
|
glViewport(0,0,s_screen->w,s_screen->h);
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -147,6 +148,7 @@ void renderbuffer::use_as_texture() {
|
|||||||
if(FramebufferName) {
|
if(FramebufferName) {
|
||||||
glBindTexture( GL_TEXTURE_2D, renderedTexture);
|
glBindTexture( GL_TEXTURE_2D, renderedTexture);
|
||||||
}
|
}
|
||||||
|
#if CAP_SDL
|
||||||
else {
|
else {
|
||||||
if(!expanded_data)
|
if(!expanded_data)
|
||||||
expanded_data = new Uint32[tx * ty];
|
expanded_data = new Uint32[tx * ty];
|
||||||
@ -155,6 +157,7 @@ void renderbuffer::use_as_texture() {
|
|||||||
glBindTexture( GL_TEXTURE_2D, renderedTexture);
|
glBindTexture( GL_TEXTURE_2D, renderedTexture);
|
||||||
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, tx, ty, 0, GL_BGRA, GL_UNSIGNED_BYTE, expanded_data );
|
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, tx, ty, 0, GL_BGRA, GL_UNSIGNED_BYTE, expanded_data );
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
90
rug.cpp
90
rug.cpp
@ -871,6 +871,20 @@ void addNewPoints() {
|
|||||||
if(qvalid != oqvalid) { printf("adding new points %4d %4d %4d %.9lf %9d %9d\n", oqvalid, qvalid, size(points), dist, dt, queueiter); }
|
if(qvalid != oqvalid) { printf("adding new points %4d %4d %4d %.9lf %9d %9d\n", oqvalid, qvalid, size(points), dist, dt, queueiter); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !CAP_SDL
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
long long getVa() {
|
||||||
|
struct timeval tval;
|
||||||
|
gettimeofday(&tval, NULL);
|
||||||
|
return tval.tv_sec * 1000000 + tval.tv_usec;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SDL_GetTicks() {
|
||||||
|
return getVa() / 1000;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void physics() {
|
void physics() {
|
||||||
|
|
||||||
if(good_shape) return;
|
if(good_shape) return;
|
||||||
@ -981,6 +995,8 @@ bool project_ods(hyperpoint azeq, hyperpoint& h1, hyperpoint& h2, bool eye) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
vector<GLfloat> vertex_array, tvertex_array;
|
||||||
|
|
||||||
void drawTriangle(triangle& t) {
|
void drawTriangle(triangle& t) {
|
||||||
using namespace hyperpoint_vec;
|
using namespace hyperpoint_vec;
|
||||||
for(int i: {0,1,2}) {
|
for(int i: {0,1,2}) {
|
||||||
@ -1054,8 +1070,10 @@ void drawTriangle(triangle& t) {
|
|||||||
glNormal3f(hc[0]/hch,hc[1]/hch,hc[2]/hch);
|
glNormal3f(hc[0]/hch,hc[1]/hch,hc[2]/hch);
|
||||||
|
|
||||||
for(int i: {0,1,2}) {
|
for(int i: {0,1,2}) {
|
||||||
glTexCoord2f(t.m[i]->x1, t.m[i]->y1);
|
tvertex_array.push_back(t.m[i]->x1);
|
||||||
glVertex3f(h[i][0], h[i][1], h[i][2]);
|
tvertex_array.push_back(t.m[i]->y1);
|
||||||
|
for(int j: {0,1,2})
|
||||||
|
vertex_array.push_back(h[i][j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1104,8 +1122,12 @@ void drawRugScene() {
|
|||||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
||||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
||||||
|
|
||||||
|
#ifndef GLES_ONLY
|
||||||
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
|
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
|
||||||
GLERR("lighting");
|
GLERR("lighting");
|
||||||
|
#else
|
||||||
|
glLightModelx(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
|
||||||
|
#endif
|
||||||
|
|
||||||
glEnable(GL_LIGHTING);
|
glEnable(GL_LIGHTING);
|
||||||
glEnable(GL_LIGHT0);
|
glEnable(GL_LIGHT0);
|
||||||
@ -1116,7 +1138,7 @@ void drawRugScene() {
|
|||||||
glClearColor(0.05,0.05,0.05,1);
|
glClearColor(0.05,0.05,0.05,1);
|
||||||
else
|
else
|
||||||
glcolorClear(backcolor << 8 | 0xFF);
|
glcolorClear(backcolor << 8 | 0xFF);
|
||||||
glClearDepth(1.0f);
|
glClearDepthf(1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
@ -1126,13 +1148,18 @@ void drawRugScene() {
|
|||||||
|
|
||||||
for(int ed=stereo::active() && stereo::mode != stereo::sODS ? -1 : 0; ed < 2; ed += 2) {
|
for(int ed=stereo::active() && stereo::mode != stereo::sODS ? -1 : 0; ed < 2; ed += 2) {
|
||||||
use_precompute = false;
|
use_precompute = false;
|
||||||
|
vertex_array.clear();
|
||||||
|
tvertex_array.clear();
|
||||||
stereo::set_mask(ed), stereo::set_viewport(ed);
|
stereo::set_mask(ed), stereo::set_viewport(ed);
|
||||||
if(ed == 1 && stereo::mode == stereo::sAnaglyph)
|
if(ed == 1 && stereo::mode == stereo::sAnaglyph)
|
||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
start_projection(ed);
|
start_projection(ed);
|
||||||
if(stereo::mode == stereo::sODS)
|
if(stereo::mode == stereo::sODS) {
|
||||||
|
#ifndef GLES_ONLY
|
||||||
glOrtho(-M_PI, M_PI, -M_PI, M_PI, 0, -M_PI * 2);
|
glOrtho(-M_PI, M_PI, -M_PI, M_PI, 0, -M_PI * 2);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
else if(rug_perspective || stereo::active()) {
|
else if(rug_perspective || stereo::active()) {
|
||||||
|
|
||||||
ld vnear = .001;
|
ld vnear = .001;
|
||||||
@ -1140,7 +1167,15 @@ void drawRugScene() {
|
|||||||
ld sca = vnear * stereo::tanfov / vid.xres;
|
ld sca = vnear * stereo::tanfov / vid.xres;
|
||||||
xview = stereo::tanfov;
|
xview = stereo::tanfov;
|
||||||
yview = stereo::tanfov * vid.yres / vid.xres;
|
yview = stereo::tanfov * vid.yres / vid.xres;
|
||||||
glFrustum(-sca * vid.xres, sca * vid.xres, -sca * vid.yres, sca * vid.yres, vnear, vfar);
|
|
||||||
|
//glFrustum(-sca * vid.xres, sca * vid.xres, -sca * vid.yres, sca * vid.yres, vnear, vfar);
|
||||||
|
|
||||||
|
GLfloat frustum[16] = {
|
||||||
|
GLfloat(vnear / sca / vid.xres), 0, 0, 0,
|
||||||
|
0, GLfloat(vnear / sca / vid.yres), 0, 0,
|
||||||
|
0, 0, GLfloat(-(vnear+vfar)/(vfar-vnear)), -1,
|
||||||
|
0, 0, GLfloat(-2*vnear*vfar/(vfar-vnear)), 1};
|
||||||
|
glMultMatrixf(frustum);
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
@ -1160,21 +1195,38 @@ void drawRugScene() {
|
|||||||
else {
|
else {
|
||||||
xview = stereo::tanfov * model_distance;
|
xview = stereo::tanfov * model_distance;
|
||||||
yview = stereo::tanfov * model_distance * vid.yres / vid.xres;
|
yview = stereo::tanfov * model_distance * vid.yres / vid.xres;
|
||||||
glOrtho(-xview, xview, yview, -yview, -1000, 1000);
|
// glOrtho(-xview, xview, yview, -yview, -1000, 1000);
|
||||||
|
|
||||||
|
GLfloat ortho[16] = {
|
||||||
|
GLfloat(1/xview), 0, 0, 0,
|
||||||
|
0, GLfloat(1/yview), 0, 0,
|
||||||
|
0, 0, GLfloat(.001), 0,
|
||||||
|
0, 0, 0, 1};
|
||||||
|
glMultMatrixf(ortho);
|
||||||
}
|
}
|
||||||
glColor4f(1.f, 1.f, 1.f, 1.f);
|
glColor4f(1.f, 1.f, 1.f, 1.f);
|
||||||
|
|
||||||
if(rug_perspective && gwhere >= gSphere) {
|
if(rug_perspective && gwhere >= gSphere) {
|
||||||
glEnable(GL_FOG);
|
glEnable(GL_FOG);
|
||||||
|
#ifndef GLES_ONLY
|
||||||
glFogi(GL_FOG_MODE, GL_LINEAR);
|
glFogi(GL_FOG_MODE, GL_LINEAR);
|
||||||
|
#else
|
||||||
|
glFogx(GL_FOG_MODE, GL_LINEAR);
|
||||||
|
#endif
|
||||||
glFogf(GL_FOG_START, 0);
|
glFogf(GL_FOG_START, 0);
|
||||||
glFogf(GL_FOG_END, gwhere == gSphere ? 10 : 4);
|
glFogf(GL_FOG_END, gwhere == gSphere ? 10 : 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
glBegin(GL_TRIANGLES);
|
|
||||||
for(int t=0; t<size(triangles); t++)
|
for(int t=0; t<size(triangles); t++)
|
||||||
drawTriangle(triangles[t]);
|
drawTriangle(triangles[t]);
|
||||||
glEnd();
|
|
||||||
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
|
glVertexPointer(3, GL_FLOAT, 0, &vertex_array[0]);
|
||||||
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
|
glTexCoordPointer(2, GL_FLOAT, 0, &tvertex_array[0]);
|
||||||
|
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, size(vertex_array)/3);
|
||||||
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
|
|
||||||
stereo::set_mask(0);
|
stereo::set_mask(0);
|
||||||
}
|
}
|
||||||
@ -1292,8 +1344,16 @@ bool handlekeys(int sym, int uni) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#if !CAP_SDL
|
#if !CAP_SDL
|
||||||
else if(uni == SDLK_PAGEUP || uni == '[') rug_perspective ? push_all_points(-.1) : model_distance /= exp(.1);
|
else if(uni == SDLK_PAGEUP || uni == '[') {
|
||||||
else if(uni == SDLK_PAGEDOWN || uni == ']') rug_perspective ? push_all_points(+.1) : model_distance *= exp(.1);
|
if(rug_perspective) push_all_points(2, -.1);
|
||||||
|
else model_distance /= exp(.1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(uni == SDLK_PAGEDOWN || uni == ']') {
|
||||||
|
if(rug_perspective) push_all_points(2, +.1);
|
||||||
|
else model_distance *= exp(.1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
@ -1321,9 +1381,9 @@ void actDraw() {
|
|||||||
transmatrix next_orientation = getOrientation();
|
transmatrix next_orientation = getOrientation();
|
||||||
apply_rotation(inverse(last_orientation) * next_orientation);
|
apply_rotation(inverse(last_orientation) * next_orientation);
|
||||||
last_orientation = next_orientation;
|
last_orientation = next_orientation;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CAP_SDL
|
#if CAP_SDL
|
||||||
Uint8 *keystate = SDL_GetKeyState(NULL);
|
Uint8 *keystate = SDL_GetKeyState(NULL);
|
||||||
int qm = 0;
|
int qm = 0;
|
||||||
@ -1626,6 +1686,7 @@ void select() {
|
|||||||
pushScreen(rug::show);
|
pushScreen(rug::show);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CAP_COMMANDLINE
|
||||||
int rugArgs() {
|
int rugArgs() {
|
||||||
using namespace arg;
|
using namespace arg;
|
||||||
|
|
||||||
@ -1678,7 +1739,8 @@ int rugArgs() {
|
|||||||
|
|
||||||
auto rug_hook =
|
auto rug_hook =
|
||||||
addHook(hooks_args, 100, rugArgs);
|
addHook(hooks_args, 100, rugArgs);
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user