Open GL API Error Reporting

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
User avatar
bogglez
Moderator
Moderator
Posts: 578
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: Open GL API Error Reporting

Post by bogglez »

PH3NOM wrote:Stride should be fine. You are misunderstanding the internal function glKosArraysTransformPositions.
That function operates internally on a vertex array that is built by the API and is guaranteed to be of fixed vertex size.
Consider the code in the same source file that builds the texture coordinates portion of the output, based on either 16bit or 8bit indices:
Spoiler!

Code: Select all

//== Texture Coordinates ==//

static inline void _glKosElementTexCoord2fU16(pvr_vertex_t *dst, GLuint count) {
    GLuint i, index;
    GLfloat *t = GL_TEXCOORD_POINTER;

    for(i = 0; i < count; i++) {
        index = GL_INDEX_POINTER_U16[i] * GL_TEXCOORD_STRIDE;
        dst[i].u = t[index];
        dst[i].v = t[index + 1];
    }
}

static inline void _glKosElementTexCoord2fU8(pvr_vertex_t *dst, GLuint count) {
    GLuint i, index;
    GLfloat *t = GL_TEXCOORD_POINTER;

    for(i = 0; i < count; i++) {
        index = GL_INDEX_POINTER_U8[i] * GL_TEXCOORD_STRIDE;
        dst[i].u = t[index];
        dst[i].v = t[index + 1];
    }
}
By chance is the code using 2D vertices in glDrawArrays?
That is currently not supported by the code in the API. glDrawArrays currently only supports 3D vertices.

Otherwise, I would need to look at the code in question and see whats going on in the API.

-Josh
Oh poop, sorry for rushing through your code too quickly. I know it doesn't support 2D vertices, but I had that issue with 3D vertices. I will test again. You can check out jae686's project and play around with it, too. I'm using that to compare our APIs for discrepancies. I'll just change the vertex format to 3D again and change the gl*Pointer calls, then report back. They're set to 2D right now because 3D didn't work in your API anyway (I first set up 3D so your API will work too).

The code I'm referring to is here: https://bitbucket.org/jae686/vidfdc/src ... ster#cl-44

EDIT:
I tested it with 3 vertex coordinates again and get buggy output. Please apply this patch to the current head of jae's repo and try it with your libgl. (silly phpbb doesn't allow .patch files)

Code: Select all

diff --git a/src/dc_render.c b/src/dc_render.c
index ae89588..8180bdf 100644
--- a/src/dc_render.c
+++ b/src/dc_render.c
@@ -18,7 +18,7 @@
 #include "matrix.h"
 
 typedef struct {
-	float x, y;
+	float x, y, z;
 	float u, v;
 } Vertex2C2T;
 
@@ -37,6 +37,7 @@ static unsigned short SCREEN_H = 480;
 static void setVertex2C2T(Vertex2C2T *vert, float x, float y, float u, float v) {
 	vert->x = x;
 	vert->y = y;
+	vert->z = 0.f;
 	vert->u = u;
 	vert->v = v;
 }
@@ -76,7 +77,9 @@ void drawSprite(float x1, float y1, float x2, float y2, float u1, float v1, floa
 	glEnable(GL_TEXTURE_2D);
 
 // Detect kgl which has a buggy glDrawArrays implementation right now, fall back to immediate mode
-#ifndef GLAPIENTRY
+
+//#ifndef GLAPIENTRY
+#if 0
 	unsigned i;
 	glBegin(GL_TRIANGLE_STRIP);
 	for(i = 0; i < 4; ++i) {
@@ -87,8 +90,8 @@ void drawSprite(float x1, float y1, float x2, float y2, float u1, float v1, floa
 
 // Use glDrawArrays with other implementations for better performance
 #else
-	glVertexPointer(2, GL_FLOAT, sizeof(Vertex2C2T), spriteVerts);
-	glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex2C2T), (char *)spriteVerts + 2 * sizeof(float));
+	glVertexPointer(3, GL_FLOAT, sizeof(Vertex2C2T), spriteVerts);
+	glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex2C2T), (char *)spriteVerts + 3 * sizeof(float));
 
 	glEnableClientState(GL_VERTEX_ARRAY);
 	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
User avatar
PH3NOM
DC Developer
DC Developer
Posts: 576
Joined: Fri Jun 18, 2010 9:29 pm
Has thanked: 0
Been thanked: 5 times

Re: Open GL API Error Reporting

Post by PH3NOM »

Strange code there...

Honestly, I am not quite sure that is really an improvement, creating and submitting a vertex array with that function setVertex2C2T for a simple quad consisting of 4 2D vertices.
It actually should be faster to use immediate mode with glKosVertex2f to render each "sprite".

In my opinion, the best use of Vertex Arrays is to create the array once, and then use it many times.
In this code, each array is created and used only once.

Anyhow, I can not compile Jae686's code ATM as it is linking to libexpat, if you can upload that lib for DC I can test the code against my API.

That said, I noticed my examples do not use a stride on the array submission, I will make a small test to confirm stride is functioning correctly.
User avatar
PH3NOM
DC Developer
DC Developer
Posts: 576
Joined: Fri Jun 18, 2010 9:29 pm
Has thanked: 0
Been thanked: 5 times

Re: Open GL API Error Reporting

Post by PH3NOM »

bogglez wrote:I found another bug affecting all gl*Pointer functions. They don't handle various strides.
For example I have a vertex struct { float x, y, z, u, v; } which is impossible to draw using glDrawArrays, because glKosArraysTransformPositions will always perform P += 3 (skips 3 floats).
Therefore kgl's glDrawArrays will silently use my u, v as the next x, y which results in garbage on screen.
Okay I just had a chance to build a demo using arrays with strides, and you are right there is a bug in the code using arrays with strides in my API.
This is a result of re-writing my old code into its current form, after implementing glDrawElements ( note this bug you noted only effects vertex positions using glDrawArrays, not glDrawElements or "all gl*Pointer functions" as you said ).

Easy fix, on gl-arrays.c, two lines of code need to be added:
on

Code: Select all

_glKosArraysTransform(GLuint count)
add the line

Code: Select all

src += GL_VERTEX_STRIDE - 3;
at the end of the while loop, and do the same to the function _glKosArraysTransformClip

Tomorrow I should be able to get a chance to submit the patch to the repository...
User avatar
bogglez
Moderator
Moderator
Posts: 578
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: Open GL API Error Reporting

Post by bogglez »

Alright, cool!
The code is meant as an intermediate step, simply to get away from immediate mode. In jae686's font rendering code it would be better to first build the list of quads and then batch submit them for example.
I made the whole setVertex thing similar to the immediate mode calls to make it easy to replace the previous code and so he's got something familiar.
Also, without benchmarking, I'm not sure about the performance.
You could use glRect instead, if you want to draw single quads btw.
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
User avatar
PH3NOM
DC Developer
DC Developer
Posts: 576
Joined: Fri Jun 18, 2010 9:29 pm
Has thanked: 0
Been thanked: 5 times

Re: Open GL API Error Reporting

Post by PH3NOM »

I see, one step closer to build once use many times :lol:

Problem with glRect is that it does not support unique texture coordinates per-vertex, so basically texturing is not possible.

That said, this morning I decided to go ahead an write that function anyway
Spoiler!

Code: Select all

GLAPI void APIENTRY glRectfv(const GLfloat *v1, const GLfloat *v2) {
    pvr_vertex_t * v = _glKosVertexBufPointer();
    
    v[0].z = v[3].z = 0;
    
    mat_trans_single3_nomod(v1[0], v1[1], v[0].z, v[0].x, v[0].y, v[0].z);
    mat_trans_single3_nomod(v2[0], v2[1], v[3].z, v[3].x, v[3].y, v[3].z);
    
    v[0].argb = v[1].argb = v[2].argb = v[3].argb = GL_KOS_VERTEX_COLOR;
    v[0].flags = v[1].flags = v[2].flags = PVR_CMD_VERTEX;
    v[3].flags = PVR_CMD_VERTEX_EOL;
    
    v[1].x = v[0].x;
    v[1].y = v[3].y;
    v[1].z = v[3].z;
    
    v[2].x = v[3].x;
    v[2].y = v[0].y;
    v[2].z = v[0].z;
    
    _glKosVertexBufAdd(4);
    
    GL_KOS_VERTEX_COUNT += 4;    
}
EDIT:
Updated code is now pushed to the repository. Let me know if that fixes the problems you experienced in your code.
User avatar
bogglez
Moderator
Moderator
Posts: 578
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: Open GL API Error Reporting

Post by bogglez »

I got some compilation errors because some *fv functions take const arrays and their prototypes don't, so I made all of those functions take const arrays, as they should:
Spoiler!

Code: Select all

diff --git a/gl-api.c b/gl-api.c
index 4a679fd..238b333 100755
--- a/gl-api.c
+++ b/gl-api.c
@@ -278,7 +278,7 @@ GLvoid APIENTRY glTexCoord2fv(const GLfloat *uv) {
 
 GLvoid APIENTRY(*glVertex3f)(GLfloat, GLfloat, GLfloat);
 
-GLvoid APIENTRY(*glVertex3fv)(GLfloat *);
+GLvoid APIENTRY(*glVertex3fv)(const GLfloat *);
 
 GLvoid APIENTRY glVertex2f(GLfloat x, GLfloat y) {
     return _glKosVertex3ft(x, y, 0.0f);
@@ -343,7 +343,7 @@ GLAPI void APIENTRY glRecti(GLint x1, GLint y1, GLint x2, GLint y2) {
 }
 
 GLAPI void APIENTRY glRectiv(const GLint *v1, const GLint *v2) {
-    return glRectfv((GLfloat *)v1, (GLfloat *)v2);
+    return glRectfv((const GLfloat *)v1, (GLfloat *)v2);
 }
 
 GLvoid APIENTRY glKosVertex2f(GLfloat x, GLfloat y) {
@@ -536,7 +536,7 @@ GLvoid _glKosVertex3fs(GLfloat x, GLfloat y, GLfloat z) {
     ++GL_KOS_VERTEX_COUNT;
 }
 
-GLvoid _glKosVertex3fsv(GLfloat *xyz) {
+GLvoid _glKosVertex3fsv(const GLfloat *xyz) {
     pvr_vertex_t *v = _glKosVertexBufPointer();
 
     mat_trans_single3_nomod(xyz[0], xyz[1], xyz[2], v->x, v->y, v->z);
@@ -563,7 +563,7 @@ GLvoid _glKosVertex3ft(GLfloat x, GLfloat y, GLfloat z) {
     ++GL_KOS_VERTEX_COUNT;
 }
 
-GLvoid _glKosVertex3ftv(GLfloat *xyz) {
+GLvoid _glKosVertex3ftv(const GLfloat *xyz) {
     pvr_vertex_t *v = _glKosVertexBufPointer();
 
     mat_trans_single3_nomod(xyz[0], xyz[1], xyz[2], v->x, v->y, v->z);
@@ -592,7 +592,7 @@ GLvoid _glKosVertex3fc(GLfloat x, GLfloat y, GLfloat z) {
     ++GL_KOS_VERTEX_COUNT;
 }
 
-GLvoid _glKosVertex3fcv(GLfloat *xyz) {
+GLvoid _glKosVertex3fcv(const GLfloat *xyz) {
     pvr_vertex_t *v = _glKosClipBufPointer();
 
     v->x = xyz[0];
@@ -638,7 +638,7 @@ GLvoid _glKosVertex3fp(GLfloat x, GLfloat y, GLfloat z) {
     _glKosVertex3fpb(x + GL_KOS_POINT_SIZE, y + GL_KOS_POINT_SIZE, z);
 }
 
-GLvoid _glKosVertex3fpv(GLfloat *xyz) {
+GLvoid _glKosVertex3fpv(const GLfloat *xyz) {
     _glKosVertex3fpa(xyz[0] - GL_KOS_POINT_SIZE, xyz[1] - GL_KOS_POINT_SIZE, xyz[2]);
     _glKosVertex3fpa(xyz[0] + GL_KOS_POINT_SIZE, xyz[1] - GL_KOS_POINT_SIZE, xyz[2]);
     _glKosVertex3fpa(xyz[0] - GL_KOS_POINT_SIZE, xyz[1] + GL_KOS_POINT_SIZE, xyz[2]);
@@ -905,4 +905,4 @@ GLuint _glKosDepthFunc() {
 
 GLubyte _glKosDepthMask() {
     return !GL_KOS_DEPTH_WRITE;
-}
\ No newline at end of file
+}
diff --git a/gl-api.h b/gl-api.h
index 7848635..9d7475b 100755
--- a/gl-api.h
+++ b/gl-api.h
@@ -92,7 +92,7 @@ unsigned int _glKosClipTriangleStripTransformed(pvr_vertex_t *src, float *w, pvr
 void _glKosInitLighting();
 void _glKosEnableLight(const GLuint light);
 void _glKosDisableLight(const GLuint light);
-void _glKosSetEyePosition(GLfloat *position);
+void _glKosSetEyePosition(const GLfloat *position);
 void _glKosVertexComputeLighting(pvr_vertex_t *v, int verts);
 void _glKosVertexLight(glVertex *P, pvr_vertex_t *v);
 unsigned int _glKosVertexLightColor(glVertex *P);
@@ -100,19 +100,19 @@ void _glKosVertexLights(glVertex *P, pvr_vertex_t *v, GLuint count);
 
 /* Vertex Position Submission Internal Functions */
 void _glKosVertex2ft(GLfloat x, GLfloat y);
-void _glKosVertex2ftv(GLfloat *xy);
+void _glKosVertex2ftv(const GLfloat *xy);
 void _glKosVertex3ft(GLfloat x, GLfloat y, GLfloat z);
-void _glKosVertex3ftv(GLfloat *xyz);
+void _glKosVertex3ftv(const GLfloat *xyz);
 void _glKosVertex3fc(GLfloat x, GLfloat y, GLfloat z);
-void _glKosVertex3fcv(GLfloat *xyz);
+void _glKosVertex3fcv(const GLfloat *xyz);
 void _glKosVertex3fp(GLfloat x, GLfloat y, GLfloat z);
-void _glKosVertex3fpv(GLfloat *xyz);
+void _glKosVertex3fpv(const GLfloat *xyz);
 void _glKosVertex3fl(GLfloat x, GLfloat y, GLfloat z);
-void _glKosVertex3flv(GLfloat *xyz);
+void _glKosVertex3flv(const GLfloat *xyz);
 void _glKosVertex3flc(GLfloat x, GLfloat y, GLfloat z);
-void _glKosVertex3flcv(GLfloat *xyz);
+void _glKosVertex3flcv(const GLfloat *xyz);
 void _glKosVertex3fs(GLfloat x, GLfloat y, GLfloat z);
-void _glKosVertex3fsv(GLfloat *xyz);
+void _glKosVertex3fsv(const GLfloat *xyz);
 
 /* Matrix Internal Functions */
 void _glKosInitMatrix();
diff --git a/gl-light.c b/gl-light.c
index a4c3ddd..9b5c859 100755
--- a/gl-light.c
+++ b/gl-light.c
@@ -51,7 +51,7 @@ GL_DEFAULT_MATERIAL = { { 0.0, 0.0, 0.0, 1.0 }, /* Emissive Color */
 
 static GLfloat GL_EYE_POSITION[3] = { 0, 0, 0 }; /* Eye Position for Specular Factor */
 
-void _glKosSetEyePosition(GLfloat *position) {  /* Called internally by glhLookAtf() */
+void _glKosSetEyePosition(const GLfloat *position) {  /* Called internally by glhLookAtf() */
     GL_EYE_POSITION[0] = position[0];
     GL_EYE_POSITION[1] = position[1];
     GL_EYE_POSITION[2] = position[2];
@@ -342,7 +342,7 @@ float FPOW(float b, float p) {
 
 /* End FPOW Implementation */
 
-void _glKosVertex3flv(GLfloat *xyz) {
+void _glKosVertex3flv(const GLfloat *xyz) {
     glVertex *v = _glKosArrayBufPtr();
 
     v->pos[0] = xyz[0];
@@ -372,7 +372,7 @@ void _glKosVertex3fl(GLfloat x, GLfloat y, GLfloat z) {
     _glKosVertex3fs(x, y, z);
 }
 
-void _glKosVertex3flcv(GLfloat *xyz) {
+void _glKosVertex3flcv(const GLfloat *xyz) {
     glVertex *v = _glKosArrayBufPtr();
 
     v->pos[0] = xyz[0];
diff --git a/include/gl.h b/include/gl.h
index f6ae8df..4d6f542 100755
--- a/include/gl.h
+++ b/include/gl.h
@@ -403,31 +403,31 @@ GLAPI void APIENTRY glEnd();
 
 /* Primitive Texture Coordinate Submission */
 GLAPI void APIENTRY glTexCoord2f(GLfloat u, GLfloat v);
-GLAPI void APIENTRY glTexCoord2fv(GLfloat *uv);
+GLAPI void APIENTRY glTexCoord2fv(const GLfloat *uv);
 
 /* Primitive Color Submission */
 GLAPI void APIENTRY glColor1ui(GLuint argb);
 GLAPI void APIENTRY glColor4ub(GLubyte r, GLubyte  g, GLubyte b, GLubyte a);
 GLAPI void APIENTRY glColor3f(GLfloat r, GLfloat g, GLfloat b);
-GLAPI void APIENTRY glColor3fv(GLfloat *rgb);
+GLAPI void APIENTRY glColor3fv(const GLfloat *rgb);
 GLAPI void APIENTRY glColor4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
-GLAPI void APIENTRY glColor4fv(GLfloat *rgba);
+GLAPI void APIENTRY glColor4fv(const GLfloat *rgba);
 
 /* Primitive Normal Submission */
 GLAPI void APIENTRY glNormal3f(float x, float y, float z);
-GLAPI void APIENTRY glNormal3fv(float *xyz);
+GLAPI void APIENTRY glNormal3fv(const float *xyz);
 
 /* Primitive 2D Position Submission */
 GLAPI void APIENTRY glVertex2f(GLfloat x, GLfloat y);
-GLAPI void APIENTRY glVertex2fv(GLfloat *xy);
+GLAPI void APIENTRY glVertex2fv(const GLfloat *xy);
 
 /* Non-Standard KOS Primitive 2D Submission.  This will perform no tranformations on the vertices. */
 GLAPI void APIENTRY glKosVertex2f(GLfloat x, GLfloat y);
-GLAPI void APIENTRY glKosVertex2fv(GLfloat *xy);
+GLAPI void APIENTRY glKosVertex2fv(const GLfloat *xy);
 
 /* Primitive 3D Position Submission */
 GLAPI void APIENTRY(*glVertex3f)(float, float, float);
-GLAPI void APIENTRY(*glVertex3fv)(float *);
+GLAPI void APIENTRY(*glVertex3fv)(const float *);
 
 /* Enable / Disable Capability */
 /* Currently Supported Capabilities:
@@ -556,8 +556,8 @@ GLAPI void APIENTRY glFogfv(GLenum pname, const GLfloat *params);
 /* Set Global Ambient Light Color */
 GLAPI void APIENTRY glKosLightAmbient3f(GLfloat r, GLfloat g, GLfloat b);
 GLAPI void APIENTRY glKosLightAmbient4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
-GLAPI void APIENTRY glKosLightAmbient3fv(GLfloat *rgb);
-GLAPI void APIENTRY glKosLightAmbient4fv(GLfloat *rgba);
+GLAPI void APIENTRY glKosLightAmbient3fv(const GLfloat *rgb);
+GLAPI void APIENTRY glKosLightAmbient4fv(const GLfloat *rgba);
 
 /* Set Individual Light Parameters */
 GLAPI void APIENTRY glLightfv(GLenum light, GLenum pname, const GLfloat *params);

The drawQuad function now works, but drawSprite doesn't display anything):
Spoiler!

Code: Select all

	glEnable(GL_TEXTURE_2D);

	glVertexPointer(3, GL_FLOAT, sizeof(Vertex2C2T), spriteVerts);
	glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex2C2T), (char *)spriteVerts + 3 * sizeof(float));

	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);

	glDisable(GL_TEXTURE_2D);
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
User avatar
Treechopper
DCEmu Newbie
DCEmu Newbie
Posts: 4
Joined: Fri Oct 31, 2014 10:55 am
Location: Texas
Has thanked: 0
Been thanked: 0

Re: Open GL API Error Reporting

Post by Treechopper »

I'm getting build errors in kos-ports related to gl-light.h.

Code: Select all

gl-light.c:100:6: error: conflicting types for ‘glNormal3fv’
In file included from gl-light.c:22:0:
include/gl.h:418:21: note: previous declaration of ‘glNormal3fv’ was here
gl-light.c:107:6: error: conflicting types for ‘glKosLightAmbient4fv’
In file included from gl-light.c:22:0:
include/gl.h:560:21: note: previous declaration of ‘glKosLightAmbient4fv’ was here
gl-light.c:121:6: error: conflicting types for ‘glKosLightAmbient3fv’
In file included from gl-light.c:22:0:
include/gl.h:559:21: note: previous declaration of ‘glKosLightAmbient3fv’ was here
In gl-light.c the functions require a const float, while the include/gl.h indicates a float or GLfloat. Which file is right?
Jae686
Insane DCEmu
Insane DCEmu
Posts: 112
Joined: Sat Sep 22, 2007 9:43 pm
Location: Braga - Portugal
Has thanked: 0
Been thanked: 0

Re: Open GL API Error Reporting

Post by Jae686 »

Good morning.
In regards to expat, I plan to have a installer script working on this holiday.


PH3NOM wrote:Strange code there...

Honestly, I am not quite sure that is really an improvement, creating and submitting a vertex array with that function setVertex2C2T for a simple quad consisting of 4 2D vertices.
It actually should be faster to use immediate mode with glKosVertex2f to render each "sprite".

In my opinion, the best use of Vertex Arrays is to create the array once, and then use it many times.
In this code, each array is created and used only once.

Anyhow, I can not compile Jae686's code ATM as it is linking to libexpat, if you can upload that lib for DC I can test the code against my API.

That said, I noticed my examples do not use a stride on the array submission, I will make a small test to confirm stride is functioning correctly.
User avatar
bogglez
Moderator
Moderator
Posts: 578
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: Open GL API Error Reporting

Post by bogglez »

Treechopper wrote:I'm getting build errors in kos-ports related to gl-light.h.

Code: Select all

gl-light.c:100:6: error: conflicting types for ‘glNormal3fv’
In file included from gl-light.c:22:0:
include/gl.h:418:21: note: previous declaration of ‘glNormal3fv’ was here
gl-light.c:107:6: error: conflicting types for ‘glKosLightAmbient4fv’
In file included from gl-light.c:22:0:
include/gl.h:560:21: note: previous declaration of ‘glKosLightAmbient4fv’ was here
gl-light.c:121:6: error: conflicting types for ‘glKosLightAmbient3fv’
In file included from gl-light.c:22:0:
include/gl.h:559:21: note: previous declaration of ‘glKosLightAmbient3fv’ was here
In gl-light.c the functions require a const float, while the include/gl.h indicates a float or GLfloat. Which file is right?
I noticed that bug in the post right above yours. They should all be const, as that's what the GL function prototype looks like.
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
User avatar
Treechopper
DCEmu Newbie
DCEmu Newbie
Posts: 4
Joined: Fri Oct 31, 2014 10:55 am
Location: Texas
Has thanked: 0
Been thanked: 0

Re: Open GL API Error Reporting

Post by Treechopper »

Thank you bogglez! Fixed that and a few other const errors and it compiled just fine.
User avatar
PH3NOM
DC Developer
DC Developer
Posts: 576
Joined: Fri Jun 18, 2010 9:29 pm
Has thanked: 0
Been thanked: 5 times

Re: Open GL API Error Reporting

Post by PH3NOM »

Sorry for that, as it is certainly a bug introduced in the last commit I made.

API will be updated to fix any lingering problems related to changing some * functions to const * functions.
User avatar
bogglez
Moderator
Moderator
Posts: 578
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: Open GL API Error Reporting

Post by bogglez »

Noticed another potential bug:
glColor does not affect glDrawArrays. I was not sure whether glColor should affect it, but
1) it sounds like glColor actually is not strictly part of immediate mode and
2) I've tried glColor before glDrawArrays on NVidia and the color was changed.
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
Jae686
Insane DCEmu
Insane DCEmu
Posts: 112
Joined: Sat Sep 22, 2007 9:43 pm
Location: Braga - Portugal
Has thanked: 0
Been thanked: 0

Re: Open GL API Error Reporting

Post by Jae686 »

I've added a expat installer script on the repo.

Give it a shoot. :D
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Open GL API Error Reporting

Post by BlueCrab »

Jae686 wrote:I've added a expat installer script on the repo.

Give it a shoot. :D
Not sure what a script is needed for... Works as easy as this for me:

Code: Select all

CC=kos-cc CXX=kos-c++ ./configure --host=sh-elf --prefix=/wherever/you/want/to/install
make all install
I guess moving the libraries into the add ons tree and linking in the includes to somewhere that's normally in the include path isn't a bad idea though. :wink:
User avatar
PH3NOM
DC Developer
DC Developer
Posts: 576
Joined: Fri Jun 18, 2010 9:29 pm
Has thanked: 0
Been thanked: 5 times

Re: Open GL API Error Reporting

Post by PH3NOM »

bogglez wrote:I got some compilation errors because some *fv functions take const arrays and their prototypes don't, so I made all of those functions take const arrays, as they should:
Spoiler!

Code: Select all

diff --git a/gl-api.c b/gl-api.c
index 4a679fd..238b333 100755
--- a/gl-api.c
+++ b/gl-api.c
@@ -278,7 +278,7 @@ GLvoid APIENTRY glTexCoord2fv(const GLfloat *uv) {
 
 GLvoid APIENTRY(*glVertex3f)(GLfloat, GLfloat, GLfloat);
 
-GLvoid APIENTRY(*glVertex3fv)(GLfloat *);
+GLvoid APIENTRY(*glVertex3fv)(const GLfloat *);
 
 GLvoid APIENTRY glVertex2f(GLfloat x, GLfloat y) {
     return _glKosVertex3ft(x, y, 0.0f);
@@ -343,7 +343,7 @@ GLAPI void APIENTRY glRecti(GLint x1, GLint y1, GLint x2, GLint y2) {
 }
 
 GLAPI void APIENTRY glRectiv(const GLint *v1, const GLint *v2) {
-    return glRectfv((GLfloat *)v1, (GLfloat *)v2);
+    return glRectfv((const GLfloat *)v1, (GLfloat *)v2);
 }
 
 GLvoid APIENTRY glKosVertex2f(GLfloat x, GLfloat y) {
@@ -536,7 +536,7 @@ GLvoid _glKosVertex3fs(GLfloat x, GLfloat y, GLfloat z) {
     ++GL_KOS_VERTEX_COUNT;
 }
 
-GLvoid _glKosVertex3fsv(GLfloat *xyz) {
+GLvoid _glKosVertex3fsv(const GLfloat *xyz) {
     pvr_vertex_t *v = _glKosVertexBufPointer();
 
     mat_trans_single3_nomod(xyz[0], xyz[1], xyz[2], v->x, v->y, v->z);
@@ -563,7 +563,7 @@ GLvoid _glKosVertex3ft(GLfloat x, GLfloat y, GLfloat z) {
     ++GL_KOS_VERTEX_COUNT;
 }
 
-GLvoid _glKosVertex3ftv(GLfloat *xyz) {
+GLvoid _glKosVertex3ftv(const GLfloat *xyz) {
     pvr_vertex_t *v = _glKosVertexBufPointer();
 
     mat_trans_single3_nomod(xyz[0], xyz[1], xyz[2], v->x, v->y, v->z);
@@ -592,7 +592,7 @@ GLvoid _glKosVertex3fc(GLfloat x, GLfloat y, GLfloat z) {
     ++GL_KOS_VERTEX_COUNT;
 }
 
-GLvoid _glKosVertex3fcv(GLfloat *xyz) {
+GLvoid _glKosVertex3fcv(const GLfloat *xyz) {
     pvr_vertex_t *v = _glKosClipBufPointer();
 
     v->x = xyz[0];
@@ -638,7 +638,7 @@ GLvoid _glKosVertex3fp(GLfloat x, GLfloat y, GLfloat z) {
     _glKosVertex3fpb(x + GL_KOS_POINT_SIZE, y + GL_KOS_POINT_SIZE, z);
 }
 
-GLvoid _glKosVertex3fpv(GLfloat *xyz) {
+GLvoid _glKosVertex3fpv(const GLfloat *xyz) {
     _glKosVertex3fpa(xyz[0] - GL_KOS_POINT_SIZE, xyz[1] - GL_KOS_POINT_SIZE, xyz[2]);
     _glKosVertex3fpa(xyz[0] + GL_KOS_POINT_SIZE, xyz[1] - GL_KOS_POINT_SIZE, xyz[2]);
     _glKosVertex3fpa(xyz[0] - GL_KOS_POINT_SIZE, xyz[1] + GL_KOS_POINT_SIZE, xyz[2]);
@@ -905,4 +905,4 @@ GLuint _glKosDepthFunc() {
 
 GLubyte _glKosDepthMask() {
     return !GL_KOS_DEPTH_WRITE;
-}
\ No newline at end of file
+}
diff --git a/gl-api.h b/gl-api.h
index 7848635..9d7475b 100755
--- a/gl-api.h
+++ b/gl-api.h
@@ -92,7 +92,7 @@ unsigned int _glKosClipTriangleStripTransformed(pvr_vertex_t *src, float *w, pvr
 void _glKosInitLighting();
 void _glKosEnableLight(const GLuint light);
 void _glKosDisableLight(const GLuint light);
-void _glKosSetEyePosition(GLfloat *position);
+void _glKosSetEyePosition(const GLfloat *position);
 void _glKosVertexComputeLighting(pvr_vertex_t *v, int verts);
 void _glKosVertexLight(glVertex *P, pvr_vertex_t *v);
 unsigned int _glKosVertexLightColor(glVertex *P);
@@ -100,19 +100,19 @@ void _glKosVertexLights(glVertex *P, pvr_vertex_t *v, GLuint count);
 
 /* Vertex Position Submission Internal Functions */
 void _glKosVertex2ft(GLfloat x, GLfloat y);
-void _glKosVertex2ftv(GLfloat *xy);
+void _glKosVertex2ftv(const GLfloat *xy);
 void _glKosVertex3ft(GLfloat x, GLfloat y, GLfloat z);
-void _glKosVertex3ftv(GLfloat *xyz);
+void _glKosVertex3ftv(const GLfloat *xyz);
 void _glKosVertex3fc(GLfloat x, GLfloat y, GLfloat z);
-void _glKosVertex3fcv(GLfloat *xyz);
+void _glKosVertex3fcv(const GLfloat *xyz);
 void _glKosVertex3fp(GLfloat x, GLfloat y, GLfloat z);
-void _glKosVertex3fpv(GLfloat *xyz);
+void _glKosVertex3fpv(const GLfloat *xyz);
 void _glKosVertex3fl(GLfloat x, GLfloat y, GLfloat z);
-void _glKosVertex3flv(GLfloat *xyz);
+void _glKosVertex3flv(const GLfloat *xyz);
 void _glKosVertex3flc(GLfloat x, GLfloat y, GLfloat z);
-void _glKosVertex3flcv(GLfloat *xyz);
+void _glKosVertex3flcv(const GLfloat *xyz);
 void _glKosVertex3fs(GLfloat x, GLfloat y, GLfloat z);
-void _glKosVertex3fsv(GLfloat *xyz);
+void _glKosVertex3fsv(const GLfloat *xyz);
 
 /* Matrix Internal Functions */
 void _glKosInitMatrix();
diff --git a/gl-light.c b/gl-light.c
index a4c3ddd..9b5c859 100755
--- a/gl-light.c
+++ b/gl-light.c
@@ -51,7 +51,7 @@ GL_DEFAULT_MATERIAL = { { 0.0, 0.0, 0.0, 1.0 }, /* Emissive Color */
 
 static GLfloat GL_EYE_POSITION[3] = { 0, 0, 0 }; /* Eye Position for Specular Factor */
 
-void _glKosSetEyePosition(GLfloat *position) {  /* Called internally by glhLookAtf() */
+void _glKosSetEyePosition(const GLfloat *position) {  /* Called internally by glhLookAtf() */
     GL_EYE_POSITION[0] = position[0];
     GL_EYE_POSITION[1] = position[1];
     GL_EYE_POSITION[2] = position[2];
@@ -342,7 +342,7 @@ float FPOW(float b, float p) {
 
 /* End FPOW Implementation */
 
-void _glKosVertex3flv(GLfloat *xyz) {
+void _glKosVertex3flv(const GLfloat *xyz) {
     glVertex *v = _glKosArrayBufPtr();
 
     v->pos[0] = xyz[0];
@@ -372,7 +372,7 @@ void _glKosVertex3fl(GLfloat x, GLfloat y, GLfloat z) {
     _glKosVertex3fs(x, y, z);
 }
 
-void _glKosVertex3flcv(GLfloat *xyz) {
+void _glKosVertex3flcv(const GLfloat *xyz) {
     glVertex *v = _glKosArrayBufPtr();
 
     v->pos[0] = xyz[0];
diff --git a/include/gl.h b/include/gl.h
index f6ae8df..4d6f542 100755
--- a/include/gl.h
+++ b/include/gl.h
@@ -403,31 +403,31 @@ GLAPI void APIENTRY glEnd();
 
 /* Primitive Texture Coordinate Submission */
 GLAPI void APIENTRY glTexCoord2f(GLfloat u, GLfloat v);
-GLAPI void APIENTRY glTexCoord2fv(GLfloat *uv);
+GLAPI void APIENTRY glTexCoord2fv(const GLfloat *uv);
 
 /* Primitive Color Submission */
 GLAPI void APIENTRY glColor1ui(GLuint argb);
 GLAPI void APIENTRY glColor4ub(GLubyte r, GLubyte  g, GLubyte b, GLubyte a);
 GLAPI void APIENTRY glColor3f(GLfloat r, GLfloat g, GLfloat b);
-GLAPI void APIENTRY glColor3fv(GLfloat *rgb);
+GLAPI void APIENTRY glColor3fv(const GLfloat *rgb);
 GLAPI void APIENTRY glColor4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
-GLAPI void APIENTRY glColor4fv(GLfloat *rgba);
+GLAPI void APIENTRY glColor4fv(const GLfloat *rgba);
 
 /* Primitive Normal Submission */
 GLAPI void APIENTRY glNormal3f(float x, float y, float z);
-GLAPI void APIENTRY glNormal3fv(float *xyz);
+GLAPI void APIENTRY glNormal3fv(const float *xyz);
 
 /* Primitive 2D Position Submission */
 GLAPI void APIENTRY glVertex2f(GLfloat x, GLfloat y);
-GLAPI void APIENTRY glVertex2fv(GLfloat *xy);
+GLAPI void APIENTRY glVertex2fv(const GLfloat *xy);
 
 /* Non-Standard KOS Primitive 2D Submission.  This will perform no tranformations on the vertices. */
 GLAPI void APIENTRY glKosVertex2f(GLfloat x, GLfloat y);
-GLAPI void APIENTRY glKosVertex2fv(GLfloat *xy);
+GLAPI void APIENTRY glKosVertex2fv(const GLfloat *xy);
 
 /* Primitive 3D Position Submission */
 GLAPI void APIENTRY(*glVertex3f)(float, float, float);
-GLAPI void APIENTRY(*glVertex3fv)(float *);
+GLAPI void APIENTRY(*glVertex3fv)(const float *);
 
 /* Enable / Disable Capability */
 /* Currently Supported Capabilities:
@@ -556,8 +556,8 @@ GLAPI void APIENTRY glFogfv(GLenum pname, const GLfloat *params);
 /* Set Global Ambient Light Color */
 GLAPI void APIENTRY glKosLightAmbient3f(GLfloat r, GLfloat g, GLfloat b);
 GLAPI void APIENTRY glKosLightAmbient4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
-GLAPI void APIENTRY glKosLightAmbient3fv(GLfloat *rgb);
-GLAPI void APIENTRY glKosLightAmbient4fv(GLfloat *rgba);
+GLAPI void APIENTRY glKosLightAmbient3fv(const GLfloat *rgb);
+GLAPI void APIENTRY glKosLightAmbient4fv(const GLfloat *rgba);
 
 /* Set Individual Light Parameters */
 GLAPI void APIENTRY glLightfv(GLenum light, GLenum pname, const GLfloat *params);

The drawQuad function now works, but drawSprite doesn't display anything):
Spoiler!

Code: Select all

	glEnable(GL_TEXTURE_2D);

	glVertexPointer(3, GL_FLOAT, sizeof(Vertex2C2T), spriteVerts);
	glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex2C2T), (char *)spriteVerts + 3 * sizeof(float));

	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);

	glDisable(GL_TEXTURE_2D);
The cont *fv function definition errors have been fixed in the latest commit.

I have also updated the example kgl/basic/zclip_arrays to demonstrate use of strided arrays.

Also, I updated the arrays submission to use the color set by glColor if no color array or normal arrays are submitted, thanks for the tip.

EDIT:
Jae686 wrote:I've added a expat installer script on the repo.

Give it a shoot. :D
Hey there. I tried it today and the script does the trick.
I only suggest returning to the original directory when done
Spoiler!
add this at start of script

Code: Select all

SOURCE_DIR=$(pwd)
add this at end of script

Code: Select all

cd $SOURCE_DIR
After getting your project compiled against my API, I decided to go ahead and add support for 2D vertices using glDrawArrays. After doing so, I realized there was problem with the way the LookAt matrix was being applied by my API.
I updated and committed the changes to the API, so make sure to update to the current build.

Although I still advise using glKosVertex2f, this code will now work with libgl (2D vertex arrays now supported):
Spoiler!

Code: Select all

void drawSprite(float x1, float y1, float x2, float y2, float u1, float v1, float u2, float v2) {
	setVertex2C2T(&spriteVerts[0], x1, y2, u1, v2);
	setVertex2C2T(&spriteVerts[1], x1, y1, u1, v1);
	setVertex2C2T(&spriteVerts[2], x2, y2, u2, v2);
	setVertex2C2T(&spriteVerts[3], x2, y1, u2, v1);
        
	glEnable(GL_TEXTURE_2D);

	glVertexPointer(2, GL_FLOAT, sizeof(Vertex2C2T), spriteVerts);
	glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex2C2T), (char *)spriteVerts + 2 * sizeof(float));

	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
	glDisableClientState(GL_VERTEX_ARRAY);

	glDisableClientState(GL_TEXTURE_COORD_ARRAY);

	glDisable(GL_TEXTURE_2D);
}
Another note, I would advise you can implment your function drawQuad like this using libgl:
Spoiler!

Code: Select all

void drawQuad(float x1, float y1, float x2, float y2) {
    glBegin(GL_POLYGON);
        glRectf(x1, y1, x2, y2);
    glEnd();
}
User avatar
bogglez
Moderator
Moderator
Posts: 578
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: Open GL API Error Reporting

Post by bogglez »

PH3NOM wrote: Another note, I would advise you can implment your function drawQuad like this using libgl:

Code: Select all

void drawQuad(float x1, float y1, float x2, float y2) {
    glBegin(GL_POLYGON);
        glRectf(x1, y1, x2, y2);
    glEnd();
}
You should not use immediate mode here, just call glRect:
GL spec wrote:GL_INVALID_OPERATION is generated if glRect is executed between the execution of glBegin and the corresponding execution of glEnd.
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
User avatar
PH3NOM
DC Developer
DC Developer
Posts: 576
Joined: Fri Jun 18, 2010 9:29 pm
Has thanked: 0
Been thanked: 5 times

Re: Open GL API Error Reporting

Post by PH3NOM »

bogglez wrote:
PH3NOM wrote: Another note, I would advise you can implment your function drawQuad like this using libgl:

Code: Select all

void drawQuad(float x1, float y1, float x2, float y2) {
    glBegin(GL_POLYGON);
        glRectf(x1, y1, x2, y2);
    glEnd();
}
You should not use immediate mode here, just call glRect:
GL spec wrote:GL_INVALID_OPERATION is generated if glRect is executed between the execution of glBegin and the corresponding execution of glEnd.
Interesting thanks! That should work just fine in libgl, as glBegin/End dont actually do anything in the case of GL_POLYGON.
User avatar
bogglez
Moderator
Moderator
Posts: 578
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: Open GL API Error Reporting

Post by bogglez »

PH3NOM wrote:
bogglez wrote:
PH3NOM wrote: Another note, I would advise you can implment your function drawQuad like this using libgl:

Code: Select all

void drawQuad(float x1, float y1, float x2, float y2) {
    glBegin(GL_POLYGON);
        glRectf(x1, y1, x2, y2);
    glEnd();
}
You should not use immediate mode here, just call glRect:
GL spec wrote:GL_INVALID_OPERATION is generated if glRect is executed between the execution of glBegin and the corresponding execution of glEnd.
Interesting thanks! That should work just fine in libgl, as glBegin/End dont actually do anything in the case of GL_POLYGON.
But it won't work on other platforms such as the PC, defeating the purpose of having a cross-platform library, so I pointed it out anyway.
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
User avatar
bogglez
Moderator
Moderator
Posts: 578
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: Open GL API Error Reporting

Post by bogglez »

Noticed a casting bug:

Code: Select all

GLAPI void APIENTRY glRectiv(const GLint *v1, const GLint *v2) {
   return glRectfv((const GLfloat *)v1, (GLfloat *)v2);
 }
You're reinterpreting memory of an int as a float, no casting will take place.

Observe:

Code: Select all

void foo(const int *v1, const int *v2) {
	printf("%g %g\n", *(const float *)v1, *(const float *)v2);
}

int main() {
	const int a = 100;
	const int b = 200;
	foo(&a, &b);
}

Output: 1.4013e-43 2.8026e-43
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
User avatar
PH3NOM
DC Developer
DC Developer
Posts: 576
Joined: Fri Jun 18, 2010 9:29 pm
Has thanked: 0
Been thanked: 5 times

Re: Open GL API Error Reporting

Post by PH3NOM »

Good observation, I have fixed that bug!
I am waiting to commit until I finish another major update I am working on ( transform and clipping in 1 pass in pure assembly = ~3.5mil verts/sec :lol: )
Post Reply