我是C++和SDL的新手; 我正在尝试使用此处的说明添加新的SDL扩展库:http://www.lazyfoo.net/SDL_tutorials/lesson03/windows/devcpp/index.php
但我得到这些错误:
3 C:\ Documents and Settings\Edmund\My Documents\C++\myprojects\SDL\SDLevent.cpp SDL/SDL_image.h:没有这样的文件或目录.
C:\ Documents and Settings\Edmund\My Documents\C++\myprojects\SDL\SDLevent.cpp在函数`SDL_Surface*load_image(std :: string)'中:
28 C:\ Documents and Settings\Edmund\My Documents\C++\myprojects\SDL\SDLevent.cpp`IMG_Load'unclaclared(首次使用此功能)
然后是一堆不合格的ID.
这是我的代码:
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include <string>
//Screen attributes
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;
//The surfaces
SDL_Surface *image = NULL;
SDL_Surface *screen = NULL;
//The event structure that will be used
SDL_Event event;
SDL_Surface *load_image( std::string filename )
{
//The image that's loaded …Run Code Online (Sandbox Code Playgroud) 我试图通过使用正弦函数创建样本数据并使用SDL播放来生成各种频率的声音.我在用
buffer[sample] = 32767 * sinf( 2 * PI * sample * sound_frequency / 44100)
Run Code Online (Sandbox Code Playgroud)
以44100的采样率生成频率 - sound_frequency声音的样本,得到44100个样本,即.1秒的样本声音并尝试使用SDL播放.当我试图为2000Hz的sound_frequency生成样本时听起来很棒.但是当试图为60000Hz的sound_frequency生成样本时,它听起来也很好.但我预计我应该只听20-20000Hz?你能帮忙找到问题吗?
考虑这个问题的好方法是什么?手柄丢失了吗?
glCreateProgram()?glCreateShader()?glGenTextures()?glGenBuffers()?
我想知道我是否正在做必要的事情(或做太多和泄漏记忆)
我在尝试编译时收到此错误:
*1> main-light.obj:错误LNK2019:未解析的外部符号_SDL_FreeSurface在函数"private:unsigned int __thiscall objloader :: loadTexture(char const*)"中引用(?loadTexture @ objloader @@ AAEIPBD @ Z)1> main- light.obj:错误LNK2019:无法解析的外部符号功能_SDL_LoadBMP_RW引用"私人:无符号整型__thiscall objloader :: loadTexture(字符常量*)"(loadTexture @ objloader @@ AAEIPBD @ Z?)1>主light.obj:错误LNK2019:在函数引用解析外部符号_SDL_RWFromFile "私人:无符号整型__thiscall objloader :: loadTexture(字符常量*)"(loadTexture @ objloader @@ AAEIPBD @ Z?)1>主light.obj:错误LNK2019:无法解析的外部符号函数"public:void __thiscall Player :: init(void)"中引用了_SDL_GetTicks(?init @ Player @@ QAEXXZ)1> main-light.obj:错误LNK2019:函数中引用的未解析的外部符号_SDL_GetKeyState"void __cdecl Control(float ,float,bool)"(?Control @@ YAXMM_N @ Z)1> main-light.obj:错误LNK2019:未解决 错误LNK2019:外部符号_SDL_WarpMouse在函数"空隙__cdecl控制(浮点型,浮点型,布尔)"(?控制@@ @ YAXMM_N Z)1>主light.obj引用在函数引用解析外部符号_SDL_GetMouseState"空隙__cdecl控制( float,float,bool)"(?Control @@ YAXMM_N @ Z)1> main-light.obj:错误LNK2019:函数"void __cdecl Control(float,float,bool)"中引用了未解析的外部符号_SDL_ShowCursor(?Control @ @ YAXMM_N @ Z)1>主light.obj:错误LNK2019:错误LNK2019:在功能_SDL_main 1中引用解析外部符号_SDL_GL_SwapBuffers>主light.obj解析外部符号在功能_SDL_main 1>主light.obj _SDL_Delay引用:错误LNK2019:解析外部符号函数_SDL_main _SDL_PollEvent引用1>主light.obj:错误LNK2019:解析外部符号_SDL_SetVideoMode在功能_SDL_main 1中引用>主light.obj:错误LNK2019:解析外部符号函数_SDL_main _SDL_Init引用1> MSVCRT.LIB(wcrtexew.obj):错误LNK2019:解析外部符号 wWinMain @在函数引用16 _ …
我找不到运行SDL2的代码示例,当我尝试使用Derelict SDL2在DMD2上编译以下代码时,我得到了上述错误.是否有一套新的SDL2初始化程序?
代码是:
import std.stdio;
import derelict.sdl2.sdl;
import derelict.sdl2.types;
import derelict.opengl3.gl3;
private import EventHub;
pragma(lib, "DerelictUtil.lib");
pragma(lib, "DerelictGL3.lib");
pragma(lib, "derelictSDL2.lib");
bool running=true;
SDL_Surface *screen;
class App{
private EventHub ehub;
private bool virgin=true;
private int w=1024, h=768, bpp=24;
private int flags=SDL_GL_DOUBLEBUFFER;//| SDL_FULLSCREEN
public void init(){
initSDL();
}
private bool initSDL(){
if(SDL_Init(SDL_INIT_VIDEO)<0){
SDL_Quit();
writeln("Error initializing SDL_Video");
writeln(SDL_GetError());
return false;
}
writeln("fred");
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 2);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
screen=SDL_SetVideoMode(w, h, bpp, flags);
return true;
} …Run Code Online (Sandbox Code Playgroud) 我不明白为什么我的SDL应用程序不会像我要的那样设置DOUBLE_BUF;
这是一个简短的代码,这个,没有参数执行打开全屏窗口,1024*768,在32 BPP模式.
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include "main.h"
SDL_Surface *screen;
Main mainstruct;
void testModesInFormat(SDL_PixelFormat * format)
{
SDL_Rect **modes;
int i;
printf("Available hardware accelerated, fullscreen modes in %d bpp:\n",
format->BitsPerPixel);
modes = SDL_ListModes(format, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_DOUBLEBUF);
// Check is there are any modes available
if(modes == (SDL_Rect **) 0)
{
printf("\tNo modes available!\n");
return;
}
// Check if our resolution is restricted
if(modes == (SDL_Rect **) - 1)
{
printf("\tAll resolutions available.\n");
}
else
{ …Run Code Online (Sandbox Code Playgroud) 我已经尝试了一切让OpenGL 3.2在我的游戏引擎中使用CG着色器进行渲染,但我没有运气.所以我决定做一个简单的小项目,但仍然着色器不起作用.从理论上讲,我的测试项目应该只渲染一个红色三角形,但它是白色的,因为着色器没有做任何事情.
我会在这里发布代码:
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <GL/glew.h>
#include <Cg/cg.h>
#include <Cg/cgGL.h>
#include <SDL2/SDL.h>
int main()
{
SDL_Window *mainwindow;
SDL_GLContext maincontext;
SDL_Init(SDL_INIT_VIDEO);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
mainwindow = SDL_CreateWindow("Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 512, 512, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
maincontext = SDL_GL_CreateContext(mainwindow);
glewExperimental = GL_TRUE;
glewInit();
_CGcontext* cgcontext;
cgcontext = cgCreateContext();
cgGLRegisterStates(cgcontext);
CGerror error;
CGeffect effect;
const char* string;
std::string shader;
shader =
"struct VS_INPUT"
"{"
" float3 pos : ATTR0;"
"};"
"struct FS_INPUT" …Run Code Online (Sandbox Code Playgroud) 我使用各种在线教程和几本书自学编程.目前它是C++.我在过去几天里做了一些OpenGL和SDL.
我有一个小程序,它创建了一个墙,阻止一个小方块穿过它.
这是我的代码:
//
// main.cpp
// SDL_Template
//
// The headers
#include <stdlib.h>
#include <string>
// SDL headers
#include <SDL/SDL.h>
#include "SDL_image/SDL_image.h"
//#include "SDL/SDL_ttf.h"
//#include "SDL/SDL_mixer.h"
// Other headers
#include <OpenGL/gl3.h>
// Screen attributes
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;
// The frame rate
const int FRAMES_PER_SECOND = 20;
// The attributes of the square
const int SQUARE_WIDTH = 20;
const int SQUARE_HEIGHT = 20;
// The surfaces …Run Code Online (Sandbox Code Playgroud) 我在C++ SDL lib中工作.我试图动态创建一些矩形.但它不起作用.我在搜索stackoverflow.com时找到的唯一解决方案是创建一个常量值,我不想这样做.
谁能帮我?
这是我的代码:
void lvl001(){
max_score = 20;
count_enemies = 2;
SDL_Surface *enemie;
SDL_Rect enemies_sources[no] , enemies[no];
enemie = SDL_LoadBMP("player.bmp");
for( int count = 1; count <= no ; count++ ){
enemies_sources[count].x = 0;
}
}
Run Code Online (Sandbox Code Playgroud)
还有一件事.如果有一个解决方案,那么如果我想blit它,我该SDL_Blit...怎么办?()?
我做了一些性能测试并得出了这个:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
for(U32 i=0;i<objectList.length();++i)
{
PC d("draw");
VoxelObject& obj = *objectList[i];
glBindVertexArray(obj.vao);
tmpM = usedView->projection * usedView->transform * obj.transform;
glUniformMatrix4fv(shader.modelViewMatrixLoc, 1, GL_FALSE, tmpM.data());
//glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, typesheet.tbo);
glUniform1i(shader.typesheetLoc, 0);
glDrawArrays(GL_TRIANGLES, 0, VoxelObject::VERTICES_PER_BOX*obj.getNumBoxes());
d.out(); // 2 calls 0.000085s and 0.000043s each
}
PC swap("swap");
SDL_GL_SwapWindow(mainWindow); // 1 call 0.007823s
swap.out();
Run Code Online (Sandbox Code Playgroud)
拨打电话SDL_GL_SwapWindow(mainWindow);比拨打电话要长200倍!根据我的理解,我认为该功能应该做的是交换缓冲区.这意味着交换所需的时间会根据屏幕尺寸进行缩放吗?不,它根据几何数量进行扩展...我在网上进行了一些搜索,我启用了双缓冲,并且关闭了vsync.我很难过.
sdl ×10
c++ ×5
opengl ×4
audio ×1
c ×1
cg-toolkit ×1
d ×1
flags ×1
glew ×1
graphics ×1
nvidia ×1
trigonometry ×1
visual-c++ ×1
wave ×1
xcode ×1