- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个简单的程序,使用 FreeGLUT、OpenGL 和 Eliot Eshelman 的一些不错的单纯形噪声函数。目标是显示一些 3D 单纯形噪声的 2D 切片,我已使用 SDL 对其进行管理。
我的问题是:我遇到了多个似乎无法解决的定义错误。
我在 Google 和这些论坛上搜索了一段时间。我了解了很多可能导致错误的事情,但我似乎无法找到我的原因。这些错误困扰了我好几个小时。
这是我的相关来源和错误输出。
请注意,除了我遇到的错误之外,可能还有更多错误,但我还没有能够调试到足够远以找到它们。
输出:
-------------- Build: Release in OpenGL Test (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -Wall -O2 -std=c++11 -IC:\freeglut\include -c "C:\OpenGL Test\OpenGL Test\main.cpp" -o obj\Release\main.o
mingw32-g++.exe -LC:\freeglut\lib -o "bin\Release\OpenGL Test.exe" obj\Release\LUtil.o obj\Release\main.o obj\Release\simplexnoise.o -s -lmingw32 -lOpenGL32 -lglu32 -lfreeglut -mwindows
obj\Release\main.o:main.cpp:(.bss+0x0): multiple definition of `textureName'
obj\Release\LUtil.o:LUtil.cpp:(.bss+0x0): first defined here
obj\Release\main.o:main.cpp:(.bss+0x20): multiple definition of `noiseImage'
obj\Release\LUtil.o:LUtil.cpp:(.bss+0x20): first defined here
obj\Release\main.o:main.cpp:(.bss+0x12c020): multiple definition of `zOffset'
obj\Release\LUtil.o:LUtil.cpp:(.bss+0x12c020): first defined here
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))
LUtil.h:
/*This source code copyrighted by Lazy Foo' Productions (2004-2013)
and may not be redistributed without written permission.*/
//Version: 001
#ifndef LUTIL_H
#define LUTIL_H
#include "LOpenGL.h"
#include "simplexnoise.h"
//Screen Constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_FPS = 60;
float zOffset = 0;
float noiseImage[640][480];
GLuint textureName;
bool initGL();
/*
Pre Condition:
-A valid OpenGL context
Post Condition:
-Initializes matrices and clear color
-Reports to console if there was an OpenGL error
-Returns false if there was an error in initialization
Side Effects:
-Projection matrix is set to identity matrix
-Modelview matrix is set to identity matrix
-Matrix mode is set to modelview
-Clear color is set to black
*/
void update();
/*
Pre Condition:
-None
Post Condition:
-Does per frame logic
Side Effects:
-None
*/
void render();
/*
Pre Condition:
-A valid OpenGL context
-Active modelview matrix
Post Condition:
-Renders the scene
Side Effects:
-Clears the color buffer
-Swaps the front/back buffer
*/
#endif
LUtil.cpp:
/*This source code copyrighted by Lazy Foo' Productions (2004-2013)
and may not be redistributed without written permission.*/
//Version: 001
#include "LUtil.h"
bool initGL()
{
//Initialize Projection Matrix
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
//Initialize Modelview Matrix
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
//Initialize clear color
glClearColor( 0.f, 0.f, 0.f, 1.f );
//Check for error
GLenum error = glGetError();
if( error != GL_NO_ERROR )
{
printf( "Error initializing OpenGL! %s\n", gluErrorString( error ) );
return false;
}
glGenTextures(1, &textureName);
glBindTexture(GL_TEXTURE_2D, textureName);
return true;
}
void update()
{
for(int y = 0; y < SCREEN_HEIGHT; y++)
{
for(int x = 0; x < SCREEN_WIDTH; x++)
{
noiseImage[x][y] = raw_noise_3d(x, y, zOffset);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, SCREEN_WIDTH, SCREEN_HEIGHT, 0, GL_RGB, GL_FLOAT, &noiseImage[0][0]);
}
}
}
void render()
{
//Clear color buffer
glClear( GL_COLOR_BUFFER_BIT );
glColor4f(1, 0.5f, 0, 1);
//Render quad
glBegin( GL_QUADS );
glTexCoord2f( -1.f, -1.f );
glTexCoord2f( -1.f, 1.f );
glTexCoord2f( 1.f, -0.f );
glTexCoord2f( 1.f, 1.f );
glEnd();
//Update screen
glutSwapBuffers();
}
主要.cpp:
/*This source code copyrighted by Lazy Foo' Productions (2004-2013)
and may not be redistributed without written permission.*/
//Version: 001
#include "LUtil.h"
void runMainLoop( int val );
/*
Pre Condition:
-Initialized freeGLUT
Post Condition:
-Calls the main loop functions and sets itself to be called back in 1000 / SCREEN_FPS milliseconds
Side Effects:
-Sets glutTimerFunc
*/
int main( int argc, char* args[] )
{
//Initialize FreeGLUT
glutInit( &argc, args );
//Create OpenGL 2.1 context
glutInitContextVersion( 4, 4 );
//Create Double Buffered Window
glutInitDisplayMode( GLUT_DOUBLE );
glutInitWindowSize( SCREEN_WIDTH, SCREEN_HEIGHT );
glutCreateWindow( "OpenGL" );
//Do post window/context creation initialization
if( !initGL() )
{
printf( "Unable to initialize graphics library!\n" );
return 1;
}
//Set rendering function
glutDisplayFunc( render );
//Set main loop
glutTimerFunc( 1000 / SCREEN_FPS, runMainLoop, 0 );
//Start GLUT main loop
glutMainLoop();
return 0;
}
void runMainLoop( int val )
{
//Frame logic
update();
render();
//Run frame one more time
glutTimerFunc( 1000 / SCREEN_FPS, runMainLoop, val );
}
据我所知,没有多重定义,但我可能是错的。再一次,如果我是提出这个问题的“那个人”,我很抱歉。
最佳答案
将全局变量的定义移动到LUtil.cpp
:
float zOffset = 0;
float noiseImage[640][480];
GLuint textureName;
然后声明LUtil.h
中的变量:
extern float zOffset;
extern float noiseImage[640][480];
extern GLuint textureName;
关于c++ - 多个定义 : Stumped,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25858847/
我有一个简单的程序,使用 FreeGLUT、OpenGL 和 Eliot Eshelman 的一些不错的单纯形噪声函数。目标是显示一些 3D 单纯形噪声的 2D 切片,我已使用 SDL 对其进行管理。
我需要 boost 决策树桩弱分类器。因此,对于每次迭代,我都必须根据某些权重来训练弱分类器。然后我将在每次迭代后更新权重。到目前为止我已经明白了。但对我来说不清楚的部分是“基于权重训练决策树桩弱分类
void dualSort(int [], double [], int); int main() { const int ARRAY_SIZE = 1000; // A
这个问题在这里已经有了答案: the behaviour of top: auto; bamboozles me (4 个答案) 关闭 7 年前。
我正在尝试使用collectiveidea的delay_job在Rails 3应用程序中发送邮件。如果我尝试定期发送邮件 (.deliver) 它工作正常,但是一旦我切换到延迟工作,事情就会崩溃。 我
如何让这个下拉菜单的名称“Tony Robbins”垂直居中?我尝试将 vertical-align:middle 添加到包含文本的 span 和包含文本的 li#drop-avatar 中。有人可以
我正在尝试通过 steam auth here。我难过的地方是使用公钥的 RSA 密码加密。可以从 here 接收要编码的参数。我用来加密密码的代码是: import base64 from Cryp
我有一个使用 RESTful 身份验证插件的 RoR 应用程序。一切都很好。我最近启用了基于 cookie 的身份验证,并且效果也很好。问题是当用户使用 cookie 进行身份验证时,我想更改默认登录
我是一名优秀的程序员,十分优秀!