栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

c26451:算式溢出:使用4字节值上的运算符*,然后将结果转换到8字节值。在调用运算符*之前将值强制转换为宽类型可避免溢出(io.2)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

c26451:算式溢出:使用4字节值上的运算符*,然后将结果转换到8字节值。在调用运算符*之前将值强制转换为宽类型可避免溢出(io.2)

openGL系列文章目录

文章目录

openGL系列文章目录前言一、错误原因二、解决例子运行效果完整代码

前言

vs2019语法报错:
c26451:算式溢出:使用4字节值上的运算符*,然后将结果转换到8字节值。在调用运算符*之前将值强制转换为宽类型可避免溢出(io.2)

一、错误原因

在c++语法中计算使用glsl(着色器编程语法)会报错,

float toRadians(float degrees)
{
	return (degrees * 2.f * 3.14 * pai / 360.0f);
}

二、解决

把上面的 2.f修改成2.0f

float toRadians(float degrees)
{
	return (degrees * 2.0f * 3.14 * pai / 360.0f);
}

例子
#include "glew/glew.h"
#include "glfw/glfw3.h"
#include "glm/glm.hpp"
#include "glm/gtc/matrix_transform.hpp"
#include "glm/gtc/type_ptr.hpp"
#include "camera.h"
#include "Utils.h"
#include "Torus.h"
#include 
#include 
#include 

using namespace std;

static const float pai = 3.1415926;

float toRadians(float degrees)
{
	return (degrees * 2.0f * 3.14 * pai / 360.0f);
}

static const int screen_width = 1920;
static const int screen_height = 1080;

int width = 0;
int height = 0;
float aspect = 0.f;

GLuint renderingProgram = 0;
static const int numVAOs = 1;
static const int numVBOs = 4;
GLuint vao[numVAOs] = { 0 };
GLuint vbo[numVBOs] = { 0 };

Torus myTorus(0.5f, 0.2f, 48);
int numTorusVertices = myTorus.getNumVertices();
int numTorusIndices = myTorus.getNumIndices();

float torusLocX = 0.f, torusLocY = 0.f, torusLocZ = 0.f;
Camera camera(glm::vec3(0.f, 0.f, 1.f));
float cameraX = 0.f, cameraY = 0.f, cameraZ = 0.f;

glm::mat4 mMat(1.f), vMat(1.f), pMat(1.f), mvMat(1.f), invTrMat(1.f), rMat(1.f);
glm::vec3 currentLightPos(0.f), transformed(0.f);

float lightPos[3] = { 0.f };

glm::vec3 lightLoc = glm::vec3(5.f, 2.f, 2.f);
float amt = 0.f;  //y轴旋转分量

// variable allocation for display
GLuint mvLoc = 0, projLoc = 0, nLoc = 0;
GLuint globalAmbLoc = 0, ambLoc = 0, diffLoc = 0, specLoc = 0, posLoc = 0, mAmbLoc = 0, mDiffLoc = 0, mSpecLoc = 0, mShinLoc = 0;

float lastframe = 0.f;
float deltaTime = 0.f;


//white light
float globalAmbient[4] = { 0.7f, 0.7f, 0.7f, 1.f };
float lightAmbient[4] = { 0.f, 0.f, 0.f, 1.f };
float lightDiffuse[4] = { 1.f, 1.f, 1.f, 1.f };
float lightSpecular[4] = { 1.f, 1.f, 1.f, 1.f };

// gold material
float* matAmb = Utils::goldAmbient();
float* matDiff = Utils::goldDiffuse();
float* matSpec = Utils::goldSpecular();
float matShin = Utils::goldShininess();

void installLights(glm::mat4 vMatrix)
{
	transformed = glm::vec3(vMatrix * glm::vec4(currentLightPos, 1.f));
	lightPos[0] = transformed.x;
	lightPos[1] = transformed.y;
	lightPos[2] = transformed.z;

	// get the locations of the light and material fields in the shader
	globalAmbLoc = glGetUniformLocation(renderingProgram, "globalAmbient");
	ambLoc = glGetUniformLocation(renderingProgram, "light.ambient");
	diffLoc = glGetUniformLocation(renderingProgram, "light.diffuse");
	specLoc = glGetUniformLocation(renderingProgram, "light.specular");
	posLoc = glGetUniformLocation(renderingProgram, "light.position");
	mAmbLoc = glGetUniformLocation(renderingProgram, "material.ambient");
	mDiffLoc = glGetUniformLocation(renderingProgram, "material.diffuse");
	mSpecLoc = glGetUniformLocation(renderingProgram, "material.specular");
	mShinLoc = glGetUniformLocation(renderingProgram, "material.shininess");

	//  set the uniform light and material values in the shader
	glProgramUniform4fv(renderingProgram, globalAmbLoc, 1, globalAmbient);
	glProgramUniform4fv(renderingProgram, ambLoc, 1, lightAmbient);
	glProgramUniform4fv(renderingProgram, diffLoc, 1, lightDiffuse);
	glProgramUniform4fv(renderingProgram, specLoc, 1, lightSpecular);
	glProgramUniform3fv(renderingProgram, posLoc, 1, lightPos);
	glProgramUniform4fv(renderingProgram, mAmbLoc, 1, matAmb);
	glProgramUniform4fv(renderingProgram, mDiffLoc, 1, matDiff);
	glProgramUniform4fv(renderingProgram, mSpecLoc, 1, matSpec);
	glProgramUniform1f(renderingProgram, mShinLoc, matShin);
}

void setupVertices(void)
{
	vector ind = myTorus.getIndices();
	vector vert = myTorus.getVertices();
	vector tex = myTorus.getTexCoords();
	vector norm = myTorus.getNormals();

	vector pValues;
	vector tValues;
	vector nValues;
	for (int i=0; i 
运行效果 

完整代码

代码下载

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/738310.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号