Skip to content

Conversation

meisei4
Copy link

@meisei4 meisei4 commented Sep 9, 2025

Decided to make a PR because the fix was a little more involved than i felt i could show on discord, and i wanted to show more cleanly where in the code im observing the fix behavior.

Issue

In the Opengl 1.1 context the colors array is getting enabled incorrectly during wire and point mode i think

Desired behavior: DrawModelWires(..., Color tint), should draw the wire model with the wires being colored by "tint"

Observed Behavior: loading an obj file and setting it to draw the model fill with WHITE and wire frame any color other than WHITE fails.

Workaround: if you nullify the .colors field in the mesh before drawing with wires or points, you can set the color in the draw function

this PR's solution: during DrawMesh, find the current GL_POLYGON_MODE and from there do not enable the GL_COLOR_ARRAY if you are in modes of GL_LINE or GL_POINT, this allows for the draw functions tint to apply without the workaround.

NOTE: I also added rlSetPointSize(float size) (and getter) to allow for glPointSize(size), because my eyes could not debug point mode and color well without this feature of increasing point size (its also a feature i would like to have for debugging in opengl1.1)

Concerns:

I am wondering if this code change has any consequences outside of what i believe to be normal behavior matching the other opengl modes now.

Images of current behavior (will only draw white wires, even when undesired -- e.g. on top of an also white model fill)
image

Images of desired behavior (custom point and wire colors over the main model color)
image

Screenshot From 2025-09-10 01-22-25

src/rmodels.c Outdated
else rlEnableStatePointer(GL_NORMAL_ARRAY, mesh.normals);

rlEnableStatePointer(GL_COLOR_ARRAY, mesh.colors);
extern void glGetIntegerv(unsigned int pname, int *data);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid this is an undesired approach...

src/rlgl.h Outdated

void rlSetPointSize(float size) { glPointSize(size); }

float rlGetPointSize(void) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not following raylib coding conventions.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to have the curly brace conform and added comments the same as Line width (I am basing the change mostly on line width)

@raysan5
Copy link
Owner

raysan5 commented Sep 9, 2025

@meisei4 I see the issue but the proposed approach should be reviewed. rmodels never calls gl*() functions directly

@meisei4
Copy link
Author

meisei4 commented Sep 9, 2025

updated with a simple null check, even with the wire and points poor solution it didnt solve the fill mode, actual solution is just if(mesh.colors), just like the rest of the mesh fields

@meisei4
Copy link
Author

meisei4 commented Sep 9, 2025

final result with the fix:
BLUE fill, RED wires, GREEN points
image

and then with a material example
Screenshot From 2025-09-10 02-46-37

@meisei4
Copy link
Author

meisei4 commented Sep 9, 2025

Updating this because actually i falsely assumed i had rebuilt everything correctly. The issue still remains with OpenGL 1.1 even with the mesh.colors null check.

The reason in my case is because LoadOBJ will always allocate WHITE/255 into the colors field for the mesh:

model.meshes[i].colors = (unsigned char *)MemAlloc(sizeof(unsigned char)*vertexCount*4);

for (int i = 0; i < 4; i++) model.meshes[meshIndex].colors[localMeshVertexCount*4 + i] = 255;

The workaround is to just set the mesh.colors to NULL after you load the obj

apologies for the sloppiness, I am still learning, and i imagine there is a more appropriate way than just inserting the opengl context macro into the LoadOBJ (Also I have a feeling this might be an issue elsewhere where for opengl 1.1 the colors can be a bit tricky to deal with smoothly in comparison to other opengl contexts)🙇‍♂️.

@raysan5 raysan5 changed the title update OpenGL 1.1 draws to allow for tint colors in GL_LINE (wires) and GL_POINT (points) modes [rlgl] Allow tint colors in GL_LINE (wires) and GL_POINT (points) draw modes on OpenGL 1.1 Sep 12, 2025
@meisei4 meisei4 force-pushed the opengl_11_pointMode_and_wireMode_color_issue branch from af115b5 to 705550e Compare September 15, 2025 18:36
}

// Set the point drawing size
void rlSetPointSize(float size) { glPointSize(size); }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid glPointSize() is not available on OpenGL ES 2.0. Please, could we avoid adding this function?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was under the impression that it would be ok, because of the equivalent pattern for WireMode (and polygon mode in general according to comments i believe) being gated by context macros:

https://github.com/raysan5/raylib/blob/master/src/rlgl.h#L1968

Would it be ok to keep it if we add the appropriate version context checks like with WireMode?🤔

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, we can use same approach

float rlGetPointSize(void)
{
float size = 0;
glGetFloatv(GL_POINT_SIZE, &size);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid GL_POINT_SIZE is not available on OpenGL ES 2.0. Please, could we avoid adding this function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants