C++을 사용하여 그래픽 코드를 작성하는 방법을 배우기 시작했습니다. 선형 보간 코드를 컴파일 할 때 코드는 실행되지 않고 VC++을 xmemory 파일로 전송합니다. 오류나 경고가 주어지지 않으므로 작업 할 것이 없습니다. 나는 무엇을 잘못 했는가? 나는 문제가 내가 벡터를 할당하는 방식과 관련이 있다고 생각한다. 그러나 나의 변화는 아무 것도 작용하지 않았다. 나는 내가 답변으로 내 생각을 쓸 것이다 질문에 코멘트를 게시 할 수 없습니다코드가 컴파일되지 않음 - xmemory로 끝남
#include "SDL.h"
#include <iostream>
#include <glm/glm.hpp>
#include <vector>
#include "SDLauxiliary.h"
using namespace std;
using glm::vec3;
using std::vector;
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
SDL_Surface* screen;
void Draw();
void Interpolate(float a, float b, vector<float>& result) {
int i = 0;
for (float x=a;x < b+1; ++x)
{
result[i] = x;
i = i + 1;
}
}
void InterpolateVec(vec3 a, vec3 b, vector<vec3>& resultvec) {
int i = 0;
for (int add=0; add < 4; ++add) {
float count1 = (b[add]-a[add])/resultvec.size() + a[add];
float count2 = (b[add]-a[add])/resultvec.size() + a[add];
float count3 = (b[add]-a[add])/resultvec.size() + a[add];
resultvec[i].x = (count1, count2, count3);
resultvec[i].y = (count1, count2, count3);
resultvec[i].z = (count1, count2, count3);
i = i + 1;
}
}
int main(int argc, char* argv[])
{
vector<float> result(10); // Create a vector width 10 floats
Interpolate(5, 14, result); // Fill it with interpolated values
for(int i=0; i < result.size(); ++i)
cout << result[i] << " "; // Print the result to the terminal
vector<vec3> resultvec(4);
vec3 a(1,4,9.2);
vec3 b(4,1,9.8);
InterpolateVec(a, b, resultvec);
for(int i=0; i<resultvec.size(); ++i)
{
cout << "("
<< resultvec[i].x << ", "
<< resultvec[i].y << ", "
<< resultvec[i].z << ") ";
}
screen = InitializeSDL(SCREEN_WIDTH, SCREEN_HEIGHT);
while(NoQuitMessageSDL())
{
Draw();
}
SDL_SaveBMP(screen, "screenshot.bmp");
return 0;
}
void Draw()
{
for(int y=0; y<SCREEN_HEIGHT; ++y)
{
for(int x=0; x<SCREEN_WIDTH; ++x)
{
vec3 color(1,0,1);
PutPixelSDL(screen, x, y, color);
}
}
if(SDL_MUSTLOCK(screen))
SDL_UnlockSurface(screen);
SDL_UpdateRect(screen, 0, 0, 0, 0);
}
당신이 할 수있는만큼 많은 코드를 제거하고 여전히 오류가 있습니다. –
아 맞아! 나는 벡터 할당을 오해했다. InterpolateVec에서 과제를 변경했는데 효과가있었습니다. – Nanaki