diff --git a/2d/gpixel.c b/2d/gpixel.c index a4cc776fe..e25324e29 100644 --- a/2d/gpixel.c +++ b/2d/gpixel.c @@ -14,14 +14,28 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "u_mem.h" #include "gr.h" #include "grdef.h" +#ifdef OGL +#include "ogl_init.h" +#endif unsigned char gr_ugpixel( grs_bitmap * bitmap, int x, int y ) { - return bitmap->bm_data[ bitmap->bm_rowsize*y + x ]; + switch (bitmap->bm_type) + { + case BM_LINEAR: + return bitmap->bm_data[ bitmap->bm_rowsize*y + x ]; + +#ifdef OGL + case BM_OGL: + return ogl_ugpixel(bitmap, x, y); +#endif + } + + return 0; } unsigned char gr_gpixel( grs_bitmap * bitmap, int x, int y ) { if ((x<0) || (y<0) || (x>=bitmap->bm_w) || (y>=bitmap->bm_h)) return 0; - return bitmap->bm_data[ bitmap->bm_rowsize*y + x ]; + return gr_ugpixel(bitmap, x, y); } diff --git a/CHANGELOG.txt b/CHANGELOG.txt index facc5a7ac..6d76afe56 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,6 +4,7 @@ D2X-Rebirth Changelog -------- main/multi.c, main/multi.h, main/net_udp.c: When possibly sending player positions prior to firing, do that before messing multibuf; Added more strict sanity checks for outgoing and incoming multi packets; Moved some general game stuff from net_udp_init() to multi_new_game() editor/meddraw.c: Set edge_list_size to Num_segments*12 to avoid crashes in the editor with certain third party levels +2d/gpixel.c, arch/ogl/gr.c, editor/meddraw.c, include/ogl_init.h, main/multi.c, main/render.c: Clicking on mine elements in the editor now works in ogl 20120414 diff --git a/arch/ogl/gr.c b/arch/ogl/gr.c index eba739ae3..ed34a5f66 100644 --- a/arch/ogl/gr.c +++ b/arch/ogl/gr.c @@ -564,6 +564,21 @@ void ogl_upixelc(int x, int y, int c) glDisableClientState(GL_COLOR_ARRAY); } +unsigned char ogl_ugpixel( grs_bitmap * bitmap, int x, int y ) +{ + GLint gl_draw_buffer; + ubyte buf[4]; + +#ifndef OGLES + glGetIntegerv(GL_DRAW_BUFFER, &gl_draw_buffer); + glReadBuffer(gl_draw_buffer); +#endif + + glReadPixels(bitmap->bm_x + x, SHEIGHT - bitmap->bm_y - y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, buf); + + return gr_find_closest_color(buf[0]/4, buf[1]/4, buf[2]/4); +} + void ogl_urect(int left,int top,int right,int bot) { GLfloat xo, yo, xf, yf, color_r, color_g, color_b, color_a; diff --git a/editor/meddraw.c b/editor/meddraw.c index 8b6313cba..2817d2b99 100644 --- a/editor/meddraw.c +++ b/editor/meddraw.c @@ -135,7 +135,13 @@ void check_segment(segment *seg) int fn; gr_setcolor(0); +#ifdef OGL + g3_end_frame(); +#endif gr_pixel(Search_x,Search_y); //set our search pixel to color zero +#ifdef OGL + g3_start_frame(); +#endif gr_setcolor(1); //and render in color one for (fn=0;fn<6;fn++) { @@ -902,7 +908,13 @@ void find_segments(short x,short y,grs_canvas *screen_canvas,editor_view *v,segm render_start_frame(); gr_setcolor(0); - gr_pixel(x,y); +#ifdef OGL + g3_end_frame(); +#endif + gr_pixel(x,y); //set our search pixel to color zero +#ifdef OGL + g3_start_frame(); +#endif gr_setcolor(1); Search_mode = -1; diff --git a/include/ogl_init.h b/include/ogl_init.h index 9b741a3e9..c2c8c4e33 100644 --- a/include/ogl_init.h +++ b/include/ogl_init.h @@ -98,6 +98,7 @@ bool ogl_ubitmapm_cs(int x, int y,int dw, int dh, grs_bitmap *bm,int c, int scal bool ogl_ubitblt_i(int dw, int dh, int dx, int dy, int sw, int sh, int sx, int sy, grs_bitmap * src, grs_bitmap * dest, int texfilt); bool ogl_ubitblt(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest); void ogl_upixelc(int x, int y, int c); +unsigned char ogl_ugpixel( grs_bitmap * bitmap, int x, int y ); void ogl_ulinec(int left, int top, int right, int bot, int c); #include "3d.h" diff --git a/main/multi.c b/main/multi.c index a97dc77be..9c28363e0 100644 --- a/main/multi.c +++ b/main/multi.c @@ -943,7 +943,7 @@ multi_send_data(char *buf, int len, int priority) { if (len != message_length[(int)buf[0]]) Error("multi_send_data: Packet type %i length: %i, expected: %i\n", buf[0], len, message_length[(int)buf[0]]); - if (buf[0] < 0 || buf[0] > MULTI_MAX_TYPE) + if (buf[0] > MULTI_MAX_TYPE) Error("multi_send_data: Illegal packet type %i\n", buf[0]); if (Game_mode & GM_NETWORK) @@ -966,9 +966,9 @@ void multi_send_data_direct(unsigned char *buf, int len, int pnum, int priority) { if (len != message_length[(int)buf[0]]) Error("multi_send_data_direct: Packet type %i length: %i, expected: %i\n", buf[0], len, message_length[(int)buf[0]]); - if (buf[0] < 0 || buf[0] > MULTI_MAX_TYPE) + if (buf[0] > MULTI_MAX_TYPE) Error("multi_send_data_direct: Illegal packet type %i\n", buf[0]); - if (pnum < 0 && pnum > MAX_NUM_NET_PLAYERS) + if (pnum < 0 || pnum > MAX_NUM_NET_PLAYERS) Error("multi_send_data_direct: Illegal player num: %i\n", pnum); switch (multi_protocol) diff --git a/main/render.c b/main/render.c index 2a15f855c..4b1ce08ac 100644 --- a/main/render.c +++ b/main/render.c @@ -356,13 +356,22 @@ void check_face(int segnum, int sidenum, int facenum, int nv, int *vp, int tmap1 } gr_setcolor(0); +#ifdef OGL + ogl_end_frame(); +#endif gr_pixel(_search_x,_search_y); //set our search pixel to color zero +#ifdef OGL + ogl_start_frame(); +#endif gr_setcolor(1); //and render in color one - save_lighting = Lighting_on; - Lighting_on = 2; - //g3_draw_poly(nv,vp); - g3_draw_tmap(nv,pointlist, uvl_copy, dyn_light, bm); - Lighting_on = save_lighting; + save_lighting = Lighting_on; + Lighting_on = 2; +#ifdef OGL + g3_draw_poly(nv,&pointlist[0]); +#else + g3_draw_tmap(nv,&pointlist[0], uvl_copy, dyn_light, bm); +#endif + Lighting_on = save_lighting; if (gr_ugpixel(&grd_curcanv->cv_bitmap,_search_x,_search_y) == 1) { found_seg = segnum; @@ -566,13 +575,25 @@ void render_object_search(object *obj) //in case the object itself is rendering color 0 gr_setcolor(0); +#ifdef OGL + ogl_end_frame(); +#endif gr_pixel(_search_x,_search_y); //set our search pixel to color zero +#ifdef OGL + ogl_start_frame(); +#endif render_object(obj); if (gr_ugpixel(&grd_curcanv->cv_bitmap,_search_x,_search_y) != 0) changed=1; gr_setcolor(1); +#ifdef OGL + ogl_end_frame(); +#endif gr_pixel(_search_x,_search_y); //set our search pixel to color zero +#ifdef OGL + ogl_start_frame(); +#endif render_object(obj); if (gr_ugpixel(&grd_curcanv->cv_bitmap,_search_x,_search_y) != 1) changed=1;