- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我刚开始使用 Visual Studio 以及库 OpenGL 和 SDL。
我在设置我的程序时遇到问题,并且在我尝试构建它时不断遇到错误。
任何人都可以帮我解决以下问题 -
Error 1 error LNK2019: unresolved external symbol __imp__glewInit@0 referenced in function _SDL_main
Error 2 error LNK2019: unresolved external symbol __imp__glewGetErrorString@4 referenced in function _SDL_main
Error 3 error LNK2001: unresolved external symbol __imp____GLEW_VERSION_3_0
Error 4 error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
Error 5 error LNK1120: 4 unresolved externals
6 IntelliSense: identifier "GLuint" is undefined
7 IntelliSense: identifier "GLuint" is undefined
这是我的代码-
主.c
#include<SDL.h>
#include<GL\glew.h>
#include <stdio.h>
char shouldExit = 0;
int main(void)
{
/* Initialize SDL *l
if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
return 1;
}
/* Create the window, OpenGL context */
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_Window* window = SDL_CreateWindow(
"TestSDL",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
640, 480,
SDL_WINDOW_OPENGL);
if (!window) {
fprintf(stderr, "Could not create window.ErrorCode = %s\n", SDL_GetError());
SDL_Quit();
return 1;
}
SDL_GL_CreateContext(window);
/* Make sure we have a recent version of OpenGL */
GLenum glewError = glewInit();
if (glewError != GLEW_OK) {
fprintf(stderr, "Could not initialize glew.ErrorCode = %s\n", glewGetErrorString(glewError));
SDL_Quit();
return 1;
}
if (!GLEW_VERSION_3_0) {
fprintf(stderr, "OpenGL max supported version is too low.\n");
SDL_Quit();
return 1;
}
/* Setup OpenGL state */
glViewport(0, 0, 640, 480);
glMatrixMode(GL_PROJECTION);
glOrtho(0, 640, 480, 0, 0, 100);
glEnable(GL_TEXTURE_2D);
/* The game loop */
while (!shouldExit) {
// Handle OS message pump
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
shouldExit = 1;
}
}
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
/* Game logic goes here */
SDL_GL_SwapWindow(window);
}
SDL_Quit();
return 0;
}
DrawUtils.c
/***********************************************************************
Utilities for loading and drawing sprites.
*/
#include<GL/glew.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<assert.h>
/* Load a file into an OpenGL texture, and return that texture. */
GLuint glTexImageTGAFile( const char* filename, int* outWidth, int* outHeight )
{
const int BPP = 4;
/* open the file */
FILE* file = fopen( filename, "rb" );
if( file == NULL ) {
fprintf( stderr, "File: %s -- Could not open for reading.\n", filename );
return 0;
}
/* skip first two bytes of data we don't need */
fseek( file, 2, SEEK_CUR );
/* read in the image type. For our purposes the image type should
* be either a 2 or a 3. */
unsigned char imageTypeCode;
fread( &imageTypeCode, 1, 1, file );
if( imageTypeCode != 2 && imageTypeCode != 3 ) {
fclose( file );
fprintf( stderr, "File: %s -- Unsupported TGA type: %d\n", filename, imageTypeCode );
return 0;
}
/* skip 9 bytes of data we don't need */
fseek( file, 9, SEEK_CUR );
/* read image dimensions */
int imageWidth = 0;
int imageHeight = 0;
int bitCount = 0;
fread( &imageWidth, sizeof( short ), 1, file );
fread( &imageHeight, sizeof( short ), 1, file );
fread( &bitCount, sizeof( unsigned char ), 1, file );
fseek( file, 1, SEEK_CUR );
/* allocate memory for image data and read it in */
unsigned char* bytes = (unsigned char*)calloc( imageWidth * imageHeight * BPP, 1 );
/* read in data */
if( bitCount == 32 ) {
int it;
for( it = 0; it != imageWidth * imageHeight; ++it ) {
bytes[ it * BPP + 0 ] = fgetc( file );
bytes[ it * BPP + 1 ] = fgetc( file );
bytes[ it * BPP + 2 ] = fgetc( file );
bytes[ it * BPP + 3 ] = fgetc( file );
}
} else {
int it;
for( it = 0; it != imageWidth * imageHeight; ++it ) {
bytes[ it * BPP + 0 ] = fgetc( file );
bytes[ it * BPP + 1 ] = fgetc( file );
bytes[ it * BPP + 2 ] = fgetc( file );
bytes[ it * BPP + 3 ] = 255;
}
}
fclose( file );
/* load into OpenGL */
GLuint tex;
glGenTextures( 1, &tex );
glBindTexture( GL_TEXTURE_2D, tex );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, imageWidth, imageHeight, 0,
GL_BGRA, GL_UNSIGNED_BYTE, bytes );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
free( bytes );
if( outWidth ) {
*outWidth = imageWidth;
}
if( outHeight ) {
*outHeight = imageHeight;
}
return tex;
}
/* Draw the sprite */
void glDrawSprite( GLuint tex, int x, int y, int w, int h )
{
glBindTexture( GL_TEXTURE_2D, tex );
glBegin( GL_QUADS );
{
glColor3ub( 255, 255, 255 );
glTexCoord2f( 0, 1 );
glVertex2i( x, y );
glTexCoord2f( 1, 1 );
glVertex2i( x + w, y );
glTexCoord2f( 1, 0 );
glVertex2i( x + w, y + h );
glTexCoord2f( 0, 0 );
glVertex2i( x, y + h );
}
glEnd();
}
DrawUtils.h
#ifndef DRAWUTILS_H
#define DRAWUTILS_H
#ifdef __cplusplus
extern "C" {
#endif
GLuint glTexImageTGAFile( const char* filename, int* outWidth, int* outHeight );
void glDrawSprite( GLuint tex, int x, int y, int w, int h );
#ifdef __cplusplus
}
#endif
#endif
我是否缺少#include?
最佳答案
不,你错过了一个图书馆。您包括 GLEW 头文件:
#include<GL\glew.h>
但是,头文件仅定义函数原型(prototype)(例如glewInit()
)——这些函数的实际实现将被存储在 .lib
(或 .a
)文件中,您必须链接该文件才能构建项目。
我已经有一段时间没有使用 Visual Studio 了,但我认为您通常会将链接器选项设置为项目配置的一部分。但是,可以在您的代码中指定链接器选项,如果您必须:
#pragma comment(lib, "glew/glew32s.lib")
请注意,#pragma
方法是特定于 MSVC 的,可能不适用于其他编译器。
如果您不愿意摆弄链接器选项,您可以随时使用 add glew.c
to your project相反。
另一件事:您在 DrawUtils.h
中使用 GLuint
,但没有包含 gl.h
或 glew.h
:
GLuint glTexImageTGAFile( const char* filename, int* outWidth, int* outHeight );
void glDrawSprite( GLuint tex, int x, int y, int w, int h );
关于c++ - 使用 SDL 和 GLEW 设置 Visual Studio 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28361887/
问题解决了 转到底部查看解决方案。 大家好,我用谷歌搜索了很长时间,但没有找到任何东西,所以,我们开始吧: 我有这样的设置: Compiler: MinGW IDE: Netbeans Library
如何在 SDL 中创建一个插入主窗口的新窗口?所以它可以是有重点的,有单独的绘图上下文和单独的处理事件。 最佳答案 窗中窗 您可以使用下面的示例在窗口中创建一个窗口。该示例将生成两个窗口,其中 sub
我是 SDL 的新手,我只是好奇为什么 sdl 使用静态和动态库?我的意思是,sdl.dll 中有哪些函数,为什么它是动态链接而不是静态链接?谢谢。 最佳答案 SDL.dll包含您在 SDL 中使用的
我通过 brew 在我的 mac 上安装了 SDL,但我无法包含它!这是我太简单的代码: #include int main(){ return 0; } 用cc编译时,CC找不到SDL.h
我正在尝试制作一个以恒定帧速率运行的 SDL 程序。但是我发现即使我的程序滞后很多并且跳过了很多帧(即使它以低帧运行并且没有渲染太多)。 你们有什么建议可以让我的程序运行更流畅吗? #include
我目前正在编写一款非常复杂和狡猾的游戏,它会让您充满敬畏和胜利 - 哦,好吧,这是 15 个谜题,我只是在熟悉 SDL。 我在窗口模式下运行,并使用 SDL_Flip 作为一般情况的页面更新,因为它会
我知道 SDL_TEXTUREACCESS_STATIC 和 SDL_TEXTUREACCESS_TARGET 之间的区别。我正在为一款游戏编写 SDL 后端,该游戏的平台无关核心不会告诉平台相关纹理
我们最近移植了 Bitfighter从 GLUT 到 SDL。这样做有很多好处,但也有一些缺点,特别是在窗口管理领域。 Bitfighter 在固定纵横比窗口(800x600 像素)中运行。用户可以将
我正在尝试使用 SDL 2.0 了解整个 2D 加速渲染过程。 所以我的问题是在屏幕上绘制圆圈最有效的方法是什么,为什么? 一些方法是: 首先创建一个软件表面,然后在该表面上绘制必要的像素,然后从该表
我正在尝试将纹理保存到 png 中,而我唯一得到的是 是屏幕的一部分的屏幕截图。 我的代码示例: src_texture = SDL_CreateTextureFromSurface( render
我正在使用 SDL1.2 在我的 openGL 框架中处理窗口管理。 程序运行时是否可以在不调用 SDL_Quit() 的情况下破坏窗口(表面)? ? 背景:我的框架实际上只是多媒体环境中的一个 gf
如何在 SDL 中缩放 Sprite ? 最佳答案 SDL 不直接提供缩放功能,但有 an additional library called SDL_gfx它提供旋转和缩放功能。还有another
我刚刚开始使用SDL2_ttf。我已经弄清楚如何使用 TTF_RenderText_Blished 在屏幕上获取一些文本,但是如何让它进行换行和自动换行? 似乎不支持\n;它只是创造一个空间而不是沿着
我安装了 FEDORA 和 SDL,并希望在编译时用 C 编程图形,我得到了很多对 SDL_MapRGB、SDL_Init 等的 undefined reference 我搜索了文件系统 SDL.dl
我在我的项目中使用 SDL 库,并且在 Windows 平台上工作。 当我决定将项目迁移到 SDL 2 时,我遇到了一个问题: SDL 1.2 中有一个选项可以将 stdout/stderr 的输出打
我正在尝试使用 Derelict 和 D 编写一个简单的图形测试程序。 当我尝试用 SDL 做几乎任何事情时,它都会出现段错误。这是有问题的代码: import std.stdio; import
我在考虑是否尝试使用 SDL 作为 DirectX 的替代品,似乎我只创建 2D 游戏,但是我找不到任何地方是否需要在最终用户计算机上安装 SDL 才能玩用 C# 开发的游戏,图形使用 SDL。 有人
我想使用 SDL_net 作为一个供少数程序使用的帮助程序库。然而,其中一些程序本身可能已经在使用 SDL。如果我理解正确的话,这意味着我在初始化/释放我的库时不能盲目使用 SDL_Init 和 SD
我希望我的游戏引擎停止将鼠标移动到中心(用于偏航和俯仰相机计算)。我写了一些应该处理它的代码,但鼠标在最小化时仍然移动。 void mainLoop() { // This is the ma
结构SDL_Keysym 有SDL_Scancode 和SDL_Keycode 成员。它们之间有什么区别?该文档并没有真正为我清除它。我都试过了,它们似乎做同样的事情。 最佳答案 参见 the SDL
我是一名优秀的程序员,十分优秀!