PortableGL icon indicating copy to clipboard operation
PortableGL copied to clipboard

Need help in implementing in game.

Open arczi84 opened this issue 1 year ago • 0 comments

Hello, congrats on this a cool project. I would like to implement PortableGL in WipeOut 1 https://github.com/phoboslab/wipeout-rewrite I have got game running, most gl function except anisotropy options links with PGL.

Added new renderer based on SOFTWARE and GL ones in platform_sdl.c :

#elif defined(RENDERER_PORTABLEGL) // ----------------------------------------------
	#define PLATFORM_WINDOW_FLAGS 0

	#define HEIGHT SYSTEM_WINDOW_HEIGHT
	#define WIDTH SYSTEM_WINDOW_WIDTH 
	static SDL_Texture *screenbuffer = NULL;
	static void *screenbuffer_pixels = NULL;
	static int screenbuffer_pitch;
	static vec2i_t screenbuffer_size = vec2i(0, 0);
	static vec2i_t screen_size = vec2i(0, 0);


	void platform_video_init(void) {
		SDL_GLContext platform_gl;
		platform_gl = SDL_GL_CreateContext(window);

		SDL_GL_SetSwapInterval(1);

		SDL_SetMainReady();
		renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE);
		if (!init_glContext(&the_context, &bbufpix, WIDTH, HEIGHT, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000)) {
				puts("Failed to initialize glContext");
				exit(0);
			}
	}

	void platform_video_cleanup() {
		if (screenbuffer) {
			SDL_DestroyTexture(screenbuffer);
		}
		SDL_DestroyRenderer(renderer);
		free_glContext(&the_context);
	}

	void platform_prepare_frame() {
		SDL_GL_SwapWindow(window); //??
		if (screen_size.x != screenbuffer_size.x || screen_size.y != screenbuffer_size.y) {
			if (screenbuffer) {
				SDL_DestroyTexture(screenbuffer);
			}
			screenbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STREAMING, WIDTH, HEIGHT);
			screenbuffer_size = screen_size;

		}
		SDL_LockTexture(screenbuffer, NULL, &screenbuffer_pixels, &screenbuffer_pitch);
	}

	void platform_end_frame() {
		screenbuffer_pixels = NULL;
		SDL_UnlockTexture(screenbuffer);
		SDL_UpdateTexture(screenbuffer, NULL, bbufpix, WIDTH * sizeof(uint32_t));
		SDL_RenderCopy(renderer, screenbuffer, NULL, NULL);
		SDL_RenderPresent(renderer);
	}

	rgba_t *platform_get_screenbuffer(int32_t *pitch) {
		*pitch = screenbuffer_pitch;
		return screenbuffer_pixels;
	}

	vec2i_t platform_screen_size() {
		int width, height;
		SDL_GetWindowSize(window, &width, &height);

			screen_size = vec2i(width, height);
		return screen_size;
	}

and in render_gl.c commented out glewInit(); and replaced glCreateProgram() :

	//GLuint program = glCreateProgram();
	GLenum flat = PGL_FLAT; 
	GLuint program = pglCreateProgram(vs, fs, 1, &flat, GL_FALSE);

End result is just blue flashing rectangle. obraz

Any help would be appreciated.

arczi84 avatar Jan 30 '24 13:01 arczi84