Giter Site home page Giter Site logo

c-chads / tinygl Goto Github PK

View Code? Open in Web Editor NEW
439.0 9.0 51.0 56.46 MB

The penultimate portable graphics library

License: Other

Makefile 0.23% C 95.69% C++ 3.69% Shell 0.07% CMake 0.32%
tinygl fabrice-bellard opengl rasterizer embedded c cpp c99 portable

tinygl's People

Contributors

b4yuan avatar ccawley2011 avatar ewpratten avatar robloach avatar starseeker avatar zodf0055980 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tinygl's Issues

TinyGL for DJGPP/OWv2 32-bit DOS?

There's some plans to port TinyGL for VGA DOS?, like the palette-indexed 8-bit support i was able to crosscompile TinyGL just fine in DJGPP 2.05 but i don't tested it yet unfortunately because it doesn't support 8-bit surfaces, i'm still on the way to integrate it with a special fork of Allegro4, to provide the framebuffer and the texture loading (which is slightly complicated compared with stb_image), probably the way TinyGL push pixels will not efficient because it doesn't use Bresenham's line-drawing algorithm or fixed point arithmetic for FPU-less CPUs which it was common at the time, but i intended to target Pentium 100MHz and MMX systems.

Thanks.

Lighting engine, strange behavior.

Hello, i would like to report a possible bug with the lighting engine.

This may be because i am forgetting a setting i need to add, but if i shine a light on a 3D model, a cube to be exact, as the model rotates the light flashes on and off depending on the rotation angle.

It seems like the light is not taking the model’s rotation angle into consideration before rendering the light effect. Is this a bug or is there a setting i am forgetting to set in my code?

If you need a video let me know. Thank you for your help.

Error “undefined reference to ‘ZB_open(int, int, int, void*)’” when using Arduino

Hello, i am having a problem using this library with an IDE that handles functions in an unusual way. The IDE is Arduino because i want to see if i can run this on a strong device like an esp32. I have a compiler error “undefined reference to ‘ZB_open(int, int, int, void*)’”. I don’t know if Arduino was even made to run this library in the first place but i got a bit curious. Arduino runs c++11 and i don’t if this library supports that version. I tried to modify the files but nothing made it work. If anyone knows a way to get past this error please tell me. Thank you for any help you can give me.

Compatibility questions.

Hello, i know this is not the best place to ask a question about compatibility, but i can’t find anywhere else to ask this.

i was wondering how flexible this library is with compatibility. Like, what languages will this work on (especially the outdated c++11), what platforms can this work on ( and if i can use Arduino IDE with strong processors), and what is the likelihood of this software running properly on older (or newer but slower) machines running outdated software versions.

if anyone is able to answer these questions, i will gladly appreciate it. Thank you for your help.

Unable to load GL_RGBA textures

Hi!

Pretty awesome additions you have made to TinyGL! I really like it! My only issue is, I procedurally generate textures with uint32_t pixels and I cannot load that. So I've added this little patch to support GL_RGBA textures (it does not do anything with the alpha channel, it just allows to load pixel buffers with uint32_t pixels).

Basically it adds a components parameter to the image_util.c functions and uses that instead of the hardcoded 3:

diff --git a/src/image_util.c b/src/image_util.c
index 53d9d54..8f3fe46 100644
--- a/src/image_util.c
+++ b/src/image_util.c
@@ -4,7 +4,7 @@
  * image conversion
  */
 
-void gl_convertRGB_to_5R6G5B(GLushort* pixmap, GLubyte* rgb, GLint xsize, GLint ysize) {
+void gl_convertRGB_to_5R6G5B(GLushort* pixmap, GLubyte* rgb, GLint xsize, GLint ysize, GLint components) {
 	GLint i, n;
 	GLubyte* p;
 
@@ -12,7 +12,7 @@ void gl_convertRGB_to_5R6G5B(GLushort* pixmap, GLubyte* rgb, GLint xsize, GLint
 	n = xsize * ysize;
 	for (i = 0; i < n; i++) {
 		pixmap[i] = ((p[0] & 0xF8) << 8) | ((p[1] & 0xFC) << 3) | ((p[2] & 0xF8) >> 3);
-		p += 3;
+		p += components;
 	}
 }
 
@@ -20,15 +20,15 @@ void gl_convertRGB_to_5R6G5B(GLushort* pixmap, GLubyte* rgb, GLint xsize, GLint
  This actually converts to ARGB!!!
  This is the format of the entire engine!!!
 */
-void gl_convertRGB_to_8A8R8G8B(GLuint* pixmap, GLubyte* rgb, GLint xsize, GLint ysize) {
+void gl_convertRGB_to_8A8R8G8B(GLuint* pixmap, GLubyte* rgb, GLint xsize, GLint ysize, GLint components) {
 	GLint i, n;
 	GLubyte* p;
 
 	p = rgb;
 	n = xsize * ysize;
 	for (i = 0; i < n; i++) {
-		pixmap[i] = (((GLuint)p[0]) << 16) | (((GLuint)p[1]) << 8) | (((GLuint)p[2]));
-		p += 3;
+		pixmap[i] = (components == 4 ? ((GLuint)p[3]) << 24 : 255) | (((GLuint)p[0]) << 16) | (((GLuint)p[1]) << 8) | (((GLuint)p[2]));
+		p += components;
 	}
 }
 
@@ -47,7 +47,7 @@ static GLint GLinterpolate_imutil(GLint v00, GLint v01, GLint v10, GLint xf, GLi
  * TODO: more accurate resampling
  */
 
-void gl_resizeImage(GLubyte* dest, GLint xsize_dest, GLint ysize_dest, GLubyte* src, GLint xsize_src, GLint ysize_src) {
+void gl_resizeImage(GLubyte* dest, GLint xsize_dest, GLint ysize_dest, GLubyte* src, GLint xsize_src, GLint ysize_src, GLint components) {
 	GLubyte *pix, *pix_src;
 	GLfloat x1, y1, x1inc, y1inc;
 	GLint xi, yi, j, xf, yf, x, y;
@@ -68,20 +68,22 @@ void gl_resizeImage(GLubyte* dest, GLint xsize_dest, GLint ysize_dest, GLubyte*
 			yf = (GLint)((y1 - floor(y1)) * INTERP_NORM);
 
 			if ((xf + yf) <= INTERP_NORM) {
-				for (j = 0; j < 3; j++) {
-					pix[j] = GLinterpolate_imutil(pix_src[(yi * xsize_src + xi) * 3 + j], pix_src[(yi * xsize_src + xi + 1) * 3 + j],
-												  pix_src[((yi + 1) * xsize_src + xi) * 3 + j], xf, yf);
+				for (j = 0; j < components; j++) {
+					pix[j] = GLinterpolate_imutil(pix_src[(yi * xsize_src + xi) * components + j],
+												  pix_src[(yi * xsize_src + xi + 1) * components + j],
+												  pix_src[((yi + 1) * xsize_src + xi) * components + j], xf, yf);
 				}
 			} else {
 				xf = INTERP_NORM - xf;
 				yf = INTERP_NORM - yf;
-				for (j = 0; j < 3; j++) {
-					pix[j] = GLinterpolate_imutil(pix_src[((yi + 1) * xsize_src + xi + 1) * 3 + j], pix_src[((yi + 1) * xsize_src + xi) * 3 + j],
-												  pix_src[(yi * xsize_src + xi + 1) * 3 + j], xf, yf);
+				for (j = 0; j < components; j++) {
+					pix[j] = GLinterpolate_imutil(pix_src[((yi + 1) * xsize_src + xi + 1) * components + j],
+												  pix_src[((yi + 1) * xsize_src + xi) * components + j],
+												  pix_src[(yi * xsize_src + xi + 1) * components + j], xf, yf);
 				}
 			}
 
-			pix += 3;
+			pix += components;
 			x1 += x1inc;
 		}
 		y1 += y1inc;
@@ -93,7 +95,7 @@ void gl_resizeImage(GLubyte* dest, GLint xsize_dest, GLint ysize_dest, GLubyte*
 
 /* resizing with no GLinterlating nor nearest pixel */
 
-void gl_resizeImageNoInterpolate(GLubyte* dest, GLint xsize_dest, GLint ysize_dest, GLubyte* src, GLint xsize_src, GLint ysize_src) {
+void gl_resizeImageNoInterpolate(GLubyte* dest, GLint xsize_dest, GLint ysize_dest, GLubyte* src, GLint xsize_src, GLint ysize_src, GLint components) {
 	GLubyte *pix, *pix_src, *pix1;
 	GLint x1, y1, x1inc, y1inc;
 	GLint xi, yi, x, y;
@@ -115,8 +117,10 @@ void gl_resizeImageNoInterpolate(GLubyte* dest, GLint xsize_dest, GLint ysize_de
 			pix[0] = pix1[0];
 			pix[1] = pix1[1];
 			pix[2] = pix1[2];
+			if(components == 4)
+				pix[3] = pix1[3];
 
-			pix += 3;
+			pix += components;
 			x1 += x1inc;
 		}
 		y1 += y1inc;
diff --git a/src/texture.c b/src/texture.c
index c2e5364..f332e8b 100644
--- a/src/texture.c
+++ b/src/texture.c
@@ -263,20 +263,18 @@ void glopTexImage1D(GLParam* p) {
 	GLint do_free=0;
 	GLContext* c = gl_get_context();
 	{
+		if (!(c->current_texture != NULL && target == GL_TEXTURE_1D && level == 0 && type == GL_UNSIGNED_BYTE && border == 0 &&
+			 ((format == GL_RGB && components == 3) || (format == GL_RGBA && components == 4))))
 #if TGL_FEATURE_ERROR_CHECK == 1
-		if (!(c->current_texture != NULL && target == GL_TEXTURE_1D && level == 0 && components == 3 && border == 0 && format == GL_RGB &&
-			  type == GL_UNSIGNED_BYTE))
 #define ERROR_FLAG GL_INVALID_ENUM
 #include "error_check.h"
 
 #else
-		if (!(c->current_texture != NULL && target == GL_TEXTURE_1D && level == 0 && components == 3 && border == 0 && format == GL_RGB &&
-			  type == GL_UNSIGNED_BYTE))
 			gl_fatal_error("glTexImage2D: combination of parameters not handled!!");
 #endif
 	}
 	if (width != TGL_FEATURE_TEXTURE_DIM || height != TGL_FEATURE_TEXTURE_DIM) {
-		pixels1 = gl_malloc(TGL_FEATURE_TEXTURE_DIM * TGL_FEATURE_TEXTURE_DIM * 3); /* GUARDED*/
+		pixels1 = gl_malloc(TGL_FEATURE_TEXTURE_DIM * TGL_FEATURE_TEXTURE_DIM * components); /* GUARDED*/
 		if (pixels1 == NULL) {
 #if TGL_FEATURE_ERROR_CHECK == 1
 #define ERROR_FLAG GL_OUT_OF_MEMORY
@@ -287,7 +285,7 @@ void glopTexImage1D(GLParam* p) {
 		}
 		/* no GLinterpolation is done here to respect the original image aliasing ! */
 		
-		gl_resizeImageNoInterpolate(pixels1, TGL_FEATURE_TEXTURE_DIM, TGL_FEATURE_TEXTURE_DIM, pixels, width, height);
+		gl_resizeImageNoInterpolate(pixels1, TGL_FEATURE_TEXTURE_DIM, TGL_FEATURE_TEXTURE_DIM, pixels, width, height, components);
 		do_free = 1;
 		width = TGL_FEATURE_TEXTURE_DIM;
 		height = TGL_FEATURE_TEXTURE_DIM; 
@@ -299,9 +297,9 @@ void glopTexImage1D(GLParam* p) {
 	im->xsize = width;
 	im->ysize = height;
 #if TGL_FEATURE_RENDER_BITS == 32
-	gl_convertRGB_to_8A8R8G8B(im->pixmap, pixels1, width, height);
+	gl_convertRGB_to_8A8R8G8B(im->pixmap, pixels1, width, height, components);
 #elif TGL_FEATURE_RENDER_BITS == 16
-	gl_convertRGB_to_5R6G5B(im->pixmap, pixels1, width, height);
+	gl_convertRGB_to_5R6G5B(im->pixmap, pixels1, width, height, components);
 #else
 #error bad TGL_FEATURE_RENDER_BITS
 #endif
@@ -323,20 +321,18 @@ void glopTexImage2D(GLParam* p) {
 	GLint do_free=0;
 	GLContext* c = gl_get_context();
 	{
+		if (!(c->current_texture != NULL && target == GL_TEXTURE_2D && level == 0 && type == GL_UNSIGNED_BYTE && border == 0 &&
+			 ((format == GL_RGB && components == 3) || (format == GL_RGBA && components == 4))))
 #if TGL_FEATURE_ERROR_CHECK == 1
-		if (!(c->current_texture != NULL && target == GL_TEXTURE_2D && level == 0 && components == 3 && border == 0 && format == GL_RGB &&
-			  type == GL_UNSIGNED_BYTE))
 #define ERROR_FLAG GL_INVALID_ENUM
 #include "error_check.h"
 
 #else
-		if (!(c->current_texture != NULL && target == GL_TEXTURE_2D && level == 0 && components == 3 && border == 0 && format == GL_RGB &&
-			  type == GL_UNSIGNED_BYTE))
 			gl_fatal_error("glTexImage2D: combination of parameters not handled!!");
 #endif
 	}
 	if (width != TGL_FEATURE_TEXTURE_DIM || height != TGL_FEATURE_TEXTURE_DIM) {
-		pixels1 = gl_malloc(TGL_FEATURE_TEXTURE_DIM * TGL_FEATURE_TEXTURE_DIM * 3); /* GUARDED*/
+		pixels1 = gl_malloc(TGL_FEATURE_TEXTURE_DIM * TGL_FEATURE_TEXTURE_DIM * components); /* GUARDED*/
 		if (pixels1 == NULL) {
 #if TGL_FEATURE_ERROR_CHECK == 1
 #define ERROR_FLAG GL_OUT_OF_MEMORY
@@ -347,7 +343,7 @@ void glopTexImage2D(GLParam* p) {
 		}
 		/* no GLinterpolation is done here to respect the original image aliasing ! */
 		
-		gl_resizeImageNoInterpolate(pixels1, TGL_FEATURE_TEXTURE_DIM, TGL_FEATURE_TEXTURE_DIM, pixels, width, height);
+		gl_resizeImageNoInterpolate(pixels1, TGL_FEATURE_TEXTURE_DIM, TGL_FEATURE_TEXTURE_DIM, pixels, width, height, components);
 		do_free = 1;
 		width = TGL_FEATURE_TEXTURE_DIM;
 		height = TGL_FEATURE_TEXTURE_DIM;
@@ -359,9 +355,9 @@ void glopTexImage2D(GLParam* p) {
 	im->xsize = width;
 	im->ysize = height;
 #if TGL_FEATURE_RENDER_BITS == 32
-	gl_convertRGB_to_8A8R8G8B(im->pixmap, pixels1, width, height);
+	gl_convertRGB_to_8A8R8G8B(im->pixmap, pixels1, width, height, components);
 #elif TGL_FEATURE_RENDER_BITS == 16
-	gl_convertRGB_to_5R6G5B(im->pixmap, pixels1, width, height);
+	gl_convertRGB_to_5R6G5B(im->pixmap, pixels1, width, height, components);
 #else
 #error Bad TGL_FEATURE_RENDER_BITS
 #endif
diff --git a/src/zgl.h b/src/zgl.h
index 77cc70a..9ad5405 100644
--- a/src/zgl.h
+++ b/src/zgl.h
@@ -432,10 +432,10 @@ void glEndTextures();
 GLTexture* alloc_texture(GLint h);
 
 /* image_util.c */
-void gl_convertRGB_to_5R6G5B(GLushort* pixmap, GLubyte* rgb, GLint xsize, GLint ysize);
-void gl_convertRGB_to_8A8R8G8B(GLuint* pixmap, GLubyte* rgb, GLint xsize, GLint ysize);
-void gl_resizeImage(GLubyte* dest, GLint xsize_dest, GLint ysize_dest, GLubyte* src, GLint xsize_src, GLint ysize_src);
-void gl_resizeImageNoInterpolate(GLubyte* dest, GLint xsize_dest, GLint ysize_dest, GLubyte* src, GLint xsize_src, GLint ysize_src);
+void gl_convertRGB_to_5R6G5B(GLushort* pixmap, GLubyte* rgb, GLint xsize, GLint ysize, GLint components);
+void gl_convertRGB_to_8A8R8G8B(GLuint* pixmap, GLubyte* rgb, GLint xsize, GLint ysize, GLint components);
+void gl_resizeImage(GLubyte* dest, GLint xsize_dest, GLint ysize_dest, GLubyte* src, GLint xsize_src, GLint ysize_src, GLint components);
+void gl_resizeImageNoInterpolate(GLubyte* dest, GLint xsize_dest, GLint ysize_dest, GLubyte* src, GLint xsize_src, GLint ysize_src, GLint components);
 
 
 

Cheers,
bzt

Expected FPS performance?

Has any benchmarking been done using tinygl and any of the larger Stanford models? I did a naive swap of the dragon model (assimp conversion of the stl model into an obj) for the extrude.obj and I'm seeing rendering performance of ~0.3 frames per second - was wondering if that is in line with what would be expected for that size of mesh?

CMake build?

Hi! Last year I was looking into tinygl a bit, but I didn't get nearly as far as you have with repairing it - nice work!

Would you be interested in a CMake build for this library? I've found it makes it easier to test on things like Windows, and it probably wouldn't be too hard to adjust my setup for your tinygl, but I thought I'd check first and see if that's something that might be of interest to you before preparing a pull request.

Cheers,
CY

Texture perspective correction is broken. Texture still warps even when enabled.

Hello, i have found a bug that involves texture perspective correction. I enabled it with glHint and i’m still seeing texture warping.

I was talking to one of the contributors on Discord, he said it will be hard to fix, then he never got back with me. I hope everything is ok.

Am I forgetting any extra steps that must be done before the perspective correction hint, or is there a hidden bug somewhere? If anyone knows i will gladly appreciate the help. Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.