Avoid all MSVC compile warnings

Most warning were related to types conversion (casting required) and unsigned/signed types comparisons.

Added preprocessor directives (_CRT_SECURE_NO_DEPRECATE; _CRT_NONSTDC_NO_DEPRECATE) to avoid warnings about unsafe functions, those functions are safe while used properly and recommended alternatives are MS only.

Some external libraries still generate warnings.
This commit is contained in:
raysan5 2020-05-06 19:12:09 +02:00
parent 9a1e934621
commit fdad1f023b
9 changed files with 140 additions and 140 deletions

View file

@ -142,8 +142,8 @@ void DrawPoint3D(Vector3 position, Color color)
rlTranslatef(position.x, position.y, position.z);
rlBegin(RL_LINES);
rlColor4ub(color.r, color.g, color.b, color.a);
rlVertex3f(0.0,0.0,0.0);
rlVertex3f(0.0,0.0,0.1);
rlVertex3f(0.0f, 0.0f, 0.0f);
rlVertex3f(0.0f, 0.0f, 0.1f);
rlEnd();
rlPopMatrix();
}
@ -863,7 +863,7 @@ Material *LoadMaterials(const char *fileName, int *materialCount)
#endif
// Set materials shader to default (DIFFUSE, SPECULAR, NORMAL)
for (int i = 0; i < count; i++) materials[i].shader = GetShaderDefault();
for (unsigned int i = 0; i < count; i++) materials[i].shader = GetShaderDefault();
*materialCount = count;
return materials;
@ -998,7 +998,7 @@ ModelAnimation *LoadModelAnimations(const char *filename, int *animCount)
fseek(iqmFile, iqm.ofs_frames, SEEK_SET);
fread(framedata, iqm.num_frames*iqm.num_framechannels*sizeof(unsigned short), 1, iqmFile);
for (int a = 0; a < iqm.num_anims; a++)
for (unsigned int a = 0; a < iqm.num_anims; a++)
{
animations[a].frameCount = anim[a].num_frames;
animations[a].boneCount = iqm.num_poses;
@ -1006,19 +1006,19 @@ ModelAnimation *LoadModelAnimations(const char *filename, int *animCount)
animations[a].framePoses = RL_MALLOC(anim[a].num_frames*sizeof(Transform *));
//animations[a].framerate = anim.framerate; // TODO: Use framerate?
for (int j = 0; j < iqm.num_poses; j++)
for (unsigned int j = 0; j < iqm.num_poses; j++)
{
strcpy(animations[a].bones[j].name, "ANIMJOINTNAME");
animations[a].bones[j].parent = poses[j].parent;
}
for (int j = 0; j < anim[a].num_frames; j++) animations[a].framePoses[j] = RL_MALLOC(iqm.num_poses*sizeof(Transform));
for (unsigned int j = 0; j < anim[a].num_frames; j++) animations[a].framePoses[j] = RL_MALLOC(iqm.num_poses*sizeof(Transform));
int dcounter = anim[a].first_frame*iqm.num_framechannels;
for (int frame = 0; frame < anim[a].num_frames; frame++)
for (unsigned int frame = 0; frame < anim[a].num_frames; frame++)
{
for (int i = 0; i < iqm.num_poses; i++)
for (unsigned int i = 0; i < iqm.num_poses; i++)
{
animations[a].framePoses[frame][i].translation.x = poses[i].channeloffset[0];
@ -1105,7 +1105,7 @@ ModelAnimation *LoadModelAnimations(const char *filename, int *animCount)
}
// Build frameposes
for (int frame = 0; frame < anim[a].num_frames; frame++)
for (unsigned int frame = 0; frame < anim[a].num_frames; frame++)
{
for (int i = 0; i < animations[a].boneCount; i++)
{
@ -2458,10 +2458,10 @@ void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rota
Color color = model.materials[model.meshMaterial[i]].maps[MAP_DIFFUSE].color;
Color colorTint = WHITE;
colorTint.r = (((float)color.r/255.0)*((float)tint.r/255.0))*255;
colorTint.g = (((float)color.g/255.0)*((float)tint.g/255.0))*255;
colorTint.b = (((float)color.b/255.0)*((float)tint.b/255.0))*255;
colorTint.a = (((float)color.a/255.0)*((float)tint.a/255.0))*255;
colorTint.r = (unsigned char)((((float)color.r/255.0)*((float)tint.r/255.0))*255.0f);
colorTint.g = (unsigned char)((((float)color.g/255.0)*((float)tint.g/255.0))*255.0f);
colorTint.b = (unsigned char)((((float)color.b/255.0)*((float)tint.b/255.0))*255.0f);
colorTint.a = (unsigned char)((((float)color.a/255.0)*((float)tint.a/255.0))*255.0f);
model.materials[model.meshMaterial[i]].maps[MAP_DIFFUSE].color = colorTint;
rlDrawMesh(model.meshes[i], model.materials[model.meshMaterial[i]], model.transform);
@ -2845,7 +2845,7 @@ static Model LoadOBJ(const char *fileName)
if (fileData != NULL)
{
int dataSize = strlen(fileData);
unsigned int dataSize = (unsigned int)strlen(fileData);
char currentDir[1024] = { 0 };
strcpy(currentDir, GetWorkingDirectory());
chdir(GetDirectoryPath(fileName));
@ -2897,7 +2897,7 @@ static Model LoadOBJ(const char *fileName)
int vtCount = 0;
int vnCount = 0;
for (int f = 0; f < attrib.num_faces; f++)
for (unsigned int f = 0; f < attrib.num_faces; f++)
{
// Get indices for the face
tinyobj_vertex_index_t idx0 = attrib.faces[3*f + 0];
@ -2934,7 +2934,7 @@ static Model LoadOBJ(const char *fileName)
}
// Init model materials
for (int m = 0; m < materialCount; m++)
for (unsigned int m = 0; m < materialCount; m++)
{
// Init material to default
// NOTE: Uses default shader, only MAP_DIFFUSE supported
@ -2970,18 +2970,18 @@ static Model LoadOBJ(const char *fileName)
model.materials[m].maps[MAP_DIFFUSE].texture = GetTextureDefault(); // Get default texture, in case no texture is defined
if (materials[m].diffuse_texname != NULL) model.materials[m].maps[MAP_DIFFUSE].texture = LoadTexture(materials[m].diffuse_texname); //char *diffuse_texname; // map_Kd
model.materials[m].maps[MAP_DIFFUSE].color = (Color){ (float)(materials[m].diffuse[0]*255.0f), (float)(materials[m].diffuse[1]*255.0f), (float)(materials[m].diffuse[2]*255.0f), 255 }; //float diffuse[3];
model.materials[m].maps[MAP_DIFFUSE].color = (Color){ (unsigned char)(materials[m].diffuse[0]*255.0f), (unsigned char)(materials[m].diffuse[1]*255.0f), (unsigned char)(materials[m].diffuse[2]*255.0f), 255 }; //float diffuse[3];
model.materials[m].maps[MAP_DIFFUSE].value = 0.0f;
if (materials[m].specular_texname != NULL) model.materials[m].maps[MAP_SPECULAR].texture = LoadTexture(materials[m].specular_texname); //char *specular_texname; // map_Ks
model.materials[m].maps[MAP_SPECULAR].color = (Color){ (float)(materials[m].specular[0]*255.0f), (float)(materials[m].specular[1]*255.0f), (float)(materials[m].specular[2]*255.0f), 255 }; //float specular[3];
model.materials[m].maps[MAP_SPECULAR].color = (Color){ (unsigned char)(materials[m].specular[0]*255.0f), (unsigned char)(materials[m].specular[1]*255.0f), (unsigned char)(materials[m].specular[2]*255.0f), 255 }; //float specular[3];
model.materials[m].maps[MAP_SPECULAR].value = 0.0f;
if (materials[m].bump_texname != NULL) model.materials[m].maps[MAP_NORMAL].texture = LoadTexture(materials[m].bump_texname); //char *bump_texname; // map_bump, bump
model.materials[m].maps[MAP_NORMAL].color = WHITE;
model.materials[m].maps[MAP_NORMAL].value = materials[m].shininess;
model.materials[m].maps[MAP_EMISSION].color = (Color){ (float)(materials[m].emission[0]*255.0f), (float)(materials[m].emission[1]*255.0f), (float)(materials[m].emission[2]*255.0f), 255 }; //float emission[3];
model.materials[m].maps[MAP_EMISSION].color = (Color){ (unsigned char)(materials[m].emission[0]*255.0f), (unsigned char)(materials[m].emission[1]*255.0f), (unsigned char)(materials[m].emission[2]*255.0f), 255 }; //float emission[3];
if (materials[m].displacement_texname != NULL) model.materials[m].maps[MAP_HEIGHT].texture = LoadTexture(materials[m].displacement_texname); //char *displacement_texname; // disp
}
@ -3175,7 +3175,7 @@ static Model LoadIQM(const char *fileName)
{
int tcounter = 0;
for (int i = imesh[m].first_triangle; i < (imesh[m].first_triangle + imesh[m].num_triangles); i++)
for (unsigned int i = imesh[m].first_triangle; i < (imesh[m].first_triangle + imesh[m].num_triangles); i++)
{
// IQM triangles are stored counter clockwise, but raylib sets opengl to clockwise drawing, so we swap them around
model.meshes[m].indices[tcounter + 2] = tri[i].vertex[0] - imesh[m].first_vertex;
@ -3190,7 +3190,7 @@ static Model LoadIQM(const char *fileName)
fseek(iqmFile, iqm.ofs_vertexarrays, SEEK_SET);
fread(va, iqm.num_vertexarrays*sizeof(IQMVertexArray), 1, iqmFile);
for (int i = 0; i < iqm.num_vertexarrays; i++)
for (unsigned int i = 0; i < iqm.num_vertexarrays; i++)
{
switch (va[i].type)
{
@ -3200,10 +3200,10 @@ static Model LoadIQM(const char *fileName)
fseek(iqmFile, va[i].offset, SEEK_SET);
fread(vertex, iqm.num_vertexes*3*sizeof(float), 1, iqmFile);
for (int m = 0; m < iqm.num_meshes; m++)
for (unsigned int m = 0; m < iqm.num_meshes; m++)
{
int vCounter = 0;
for (int i = imesh[m].first_vertex*3; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*3; i++)
for (unsigned int i = imesh[m].first_vertex*3; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*3; i++)
{
model.meshes[m].vertices[vCounter] = vertex[i];
model.meshes[m].animVertices[vCounter] = vertex[i];
@ -3217,10 +3217,10 @@ static Model LoadIQM(const char *fileName)
fseek(iqmFile, va[i].offset, SEEK_SET);
fread(normal, iqm.num_vertexes*3*sizeof(float), 1, iqmFile);
for (int m = 0; m < iqm.num_meshes; m++)
for (unsigned int m = 0; m < iqm.num_meshes; m++)
{
int vCounter = 0;
for (int i = imesh[m].first_vertex*3; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*3; i++)
for (unsigned int i = imesh[m].first_vertex*3; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*3; i++)
{
model.meshes[m].normals[vCounter] = normal[i];
model.meshes[m].animNormals[vCounter] = normal[i];
@ -3234,10 +3234,10 @@ static Model LoadIQM(const char *fileName)
fseek(iqmFile, va[i].offset, SEEK_SET);
fread(text, iqm.num_vertexes*2*sizeof(float), 1, iqmFile);
for (int m = 0; m < iqm.num_meshes; m++)
for (unsigned int m = 0; m < iqm.num_meshes; m++)
{
int vCounter = 0;
for (int i = imesh[m].first_vertex*2; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*2; i++)
for (unsigned int i = imesh[m].first_vertex*2; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*2; i++)
{
model.meshes[m].texcoords[vCounter] = text[i];
vCounter++;
@ -3250,10 +3250,10 @@ static Model LoadIQM(const char *fileName)
fseek(iqmFile, va[i].offset, SEEK_SET);
fread(blendi, iqm.num_vertexes*4*sizeof(char), 1, iqmFile);
for (int m = 0; m < iqm.num_meshes; m++)
for (unsigned int m = 0; m < iqm.num_meshes; m++)
{
int boneCounter = 0;
for (int i = imesh[m].first_vertex*4; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*4; i++)
for (unsigned int i = imesh[m].first_vertex*4; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*4; i++)
{
model.meshes[m].boneIds[boneCounter] = blendi[i];
boneCounter++;
@ -3266,10 +3266,10 @@ static Model LoadIQM(const char *fileName)
fseek(iqmFile, va[i].offset, SEEK_SET);
fread(blendw, iqm.num_vertexes*4*sizeof(unsigned char), 1, iqmFile);
for (int m = 0; m < iqm.num_meshes; m++)
for (unsigned int m = 0; m < iqm.num_meshes; m++)
{
int boneCounter = 0;
for (int i = imesh[m].first_vertex*4; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*4; i++)
for (unsigned int i = imesh[m].first_vertex*4; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*4; i++)
{
model.meshes[m].boneWeights[boneCounter] = blendw[i]/255.0f;
boneCounter++;
@ -3288,7 +3288,7 @@ static Model LoadIQM(const char *fileName)
model.bones = RL_MALLOC(iqm.num_joints*sizeof(BoneInfo));
model.bindPose = RL_MALLOC(iqm.num_joints*sizeof(Transform));
for (int i = 0; i < iqm.num_joints; i++)
for (unsigned int i = 0; i < iqm.num_joints; i++)
{
// Bones
model.bones[i].parent = ijoint[i].parent;
@ -3460,17 +3460,17 @@ static Image LoadImageFromCgltfImage(cgltf_image *image, const char *texPath, Co
else if (image->buffer_view)
{
unsigned char *data = RL_MALLOC(image->buffer_view->size);
int n = image->buffer_view->offset;
int stride = image->buffer_view->stride ? image->buffer_view->stride : 1;
int n = (int)image->buffer_view->offset;
int stride = (int)image->buffer_view->stride ? (int)image->buffer_view->stride : 1;
for (int i = 0; i < image->buffer_view->size; i++)
for (unsigned int i = 0; i < image->buffer_view->size; i++)
{
data[i] = ((unsigned char *)image->buffer_view->buffer->data)[n];
n += stride;
}
int width, height;
unsigned char *raw = stbi_load_from_memory(data, image->buffer_view->size, &width, &height, NULL, 4);
unsigned char *raw = stbi_load_from_memory(data, (int)image->buffer_view->size, &width, &height, NULL, 4);
free(data);
rimage.data = raw;
@ -3511,12 +3511,12 @@ static Model LoadGLTF(const char *fileName)
#define LOAD_ACCESSOR(type, nbcomp, acc, dst) \
{ \
int n = 0; \
type* buf = (type*)acc->buffer_view->buffer->data+acc->buffer_view->offset/sizeof(type)+acc->offset/sizeof(type); \
for (int k = 0; k < acc->count; k++) {\
type* buf = (type*)acc->buffer_view->buffer->data + acc->buffer_view->offset/sizeof(type) + acc->offset/sizeof(type); \
for (unsigned int k = 0; k < acc->count; k++) {\
for (int l = 0; l < nbcomp; l++) {\
dst[nbcomp*k+l] = buf[n+l];\
dst[nbcomp*k + l] = buf[n + l];\
}\
n += acc->stride/sizeof(type);\
n += (int)(acc->stride/sizeof(type));\
}\
}
@ -3544,12 +3544,12 @@ static Model LoadGLTF(const char *fileName)
int primitivesCount = 0;
for (int i = 0; i < data->meshes_count; i++) primitivesCount += (int)data->meshes[i].primitives_count;
for (unsigned int i = 0; i < data->meshes_count; i++) primitivesCount += (int)data->meshes[i].primitives_count;
// Process glTF data and map to model
model.meshCount = primitivesCount;
model.meshes = RL_CALLOC(model.meshCount, sizeof(Mesh));
model.materialCount = data->materials_count + 1;
model.materialCount = (int)data->materials_count + 1;
model.materials = RL_MALLOC(model.materialCount*sizeof(Material));
model.meshMaterial = RL_MALLOC(model.meshCount*sizeof(int));
@ -3625,16 +3625,16 @@ static Model LoadGLTF(const char *fileName)
int primitiveIndex = 0;
for (int i = 0; i < data->meshes_count; i++)
for (unsigned int i = 0; i < data->meshes_count; i++)
{
for (int p = 0; p < data->meshes[i].primitives_count; p++)
for (unsigned int p = 0; p < data->meshes[i].primitives_count; p++)
{
for (int j = 0; j < data->meshes[i].primitives[p].attributes_count; j++)
for (unsigned int j = 0; j < data->meshes[i].primitives[p].attributes_count; j++)
{
if (data->meshes[i].primitives[p].attributes[j].type == cgltf_attribute_type_position)
{
cgltf_accessor *acc = data->meshes[i].primitives[p].attributes[j].data;
model.meshes[primitiveIndex].vertexCount = acc->count;
model.meshes[primitiveIndex].vertexCount = (int)acc->count;
model.meshes[primitiveIndex].vertices = RL_MALLOC(sizeof(float)*model.meshes[primitiveIndex].vertexCount*3);
LOAD_ACCESSOR(float, 3, acc, model.meshes[primitiveIndex].vertices)
@ -3669,7 +3669,7 @@ static Model LoadGLTF(const char *fileName)
{
if (acc->component_type == cgltf_component_type_r_16u)
{
model.meshes[primitiveIndex].triangleCount = acc->count/3;
model.meshes[primitiveIndex].triangleCount = (int)acc->count/3;
model.meshes[primitiveIndex].indices = RL_MALLOC(sizeof(unsigned short)*model.meshes[primitiveIndex].triangleCount*3);
LOAD_ACCESSOR(unsigned short, 1, acc, model.meshes[primitiveIndex].indices)
}
@ -3688,7 +3688,7 @@ static Model LoadGLTF(const char *fileName)
if (data->meshes[i].primitives[p].material)
{
// Compute the offset
model.meshMaterial[primitiveIndex] = data->meshes[i].primitives[p].material - data->materials;
model.meshMaterial[primitiveIndex] = (int)(data->meshes[i].primitives[p].material - data->materials);
}
else
{