Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > C/C++ программирование > Общие вопросы C/C++
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 25.07.2017, 11:25   #1
dimaSlon
Форумчанин
 
Регистрация: 24.06.2017
Сообщений: 160
По умолчанию Не компилируется программа

Я написал програму которая должна выводить текст на екран. Если все в олном файле все норм работает. но я решил создать клас и немного коду туда перенести. И теперь крешится. и я не пойму почему
Хедер
Код:
#pragma once

#include <SDL.h>
#include <SDL_ttf.h>
#include <conio.h>
#include <iostream>
#include <memory>
#include <functional>

using SDLQuiter = std::unique_ptr<void, std::function<void(void*)>>;
using SDLWindowPointer = std::unique_ptr<SDL_Window, std::function<void(SDL_Window*)>>;
using SDLRendererPointer = std::unique_ptr<SDL_Renderer, std::function<void(SDL_Renderer*)>>;
using SDLSurfacePointer = std::unique_ptr<SDL_Surface, std::function<void(SDL_Surface*)>>;
using SDLTexturePointer = std::unique_ptr<SDL_Texture, std::function<void(SDL_Texture*)>>;
using TTFFontPointer = std::unique_ptr<TTF_Font, std::function<void(TTF_Font*)>>;

class RenderStartMenu 
{
public:
	RenderStartMenu();
	RenderStartMenu(SDLRendererPointer& renderer, SDLSurfacePointer& marioTextSurface, TTFFontPointer& marioTextFont, SDLTexturePointer& marioTextTexture, SDL_Rect& marioTextRect,
		SDLSurfacePointer& enterTextSurface, TTFFontPointer& enterTextFont, SDLTexturePointer& enterTextTexture, SDL_Rect& enterTextRect, const int windowWidth, const int windowHeight);
	~RenderStartMenu();

private:
	SDLRendererPointer mRenderer;
	SDLSurfacePointer mMarioTextSurface;
	TTFFontPointer mMarioTextFont;
	SDLTexturePointer mMarioTextTexture;
	SDL_Rect mMarioTextRect;
	SDLSurfacePointer mEnterTextSurface;
	TTFFontPointer mEnterTextFont;
	SDLTexturePointer mEnterTextTexture;
	SDL_Rect mEnterTextRect;
	int mWindowWidth;
	int mWindowHeight;
};
dimaSlon вне форума Ответить с цитированием
Старый 25.07.2017, 11:25   #2
dimaSlon
Форумчанин
 
Регистрация: 24.06.2017
Сообщений: 160
По умолчанию

СРР
Код:
#include "RenderStartMenu.h"

RenderStartMenu::RenderStartMenu()
	: mRenderer(nullptr)
	, mMarioTextSurface(nullptr)
	, mMarioTextFont(nullptr)
	, mMarioTextTexture(nullptr)
	, mMarioTextRect()
	, mEnterTextSurface(nullptr)
	, mEnterTextFont(nullptr)
	, mEnterTextTexture(nullptr)
	, mEnterTextRect()
	, mWindowWidth(0)
	, mWindowHeight(0)
{}

RenderStartMenu::RenderStartMenu(SDLRendererPointer& renderer, SDLSurfacePointer& marioTextSurface, TTFFontPointer& marioTextFont, SDLTexturePointer& marioTextTexture, SDL_Rect& marioTextRect,
	SDLSurfacePointer& enterTextSurface, TTFFontPointer& enterTextFont, SDLTexturePointer& enterTextTexture, SDL_Rect& enterTextRect, const int windowWidth, const int windowHeight)
	: mRenderer(renderer.get())
	, mMarioTextSurface(marioTextSurface.get())
    , mMarioTextFont(marioTextFont.get())
	, mMarioTextTexture(marioTextTexture.get())
	, mMarioTextRect(marioTextRect)
	, mEnterTextSurface(enterTextSurface.get())
	, mEnterTextFont(enterTextFont.get())
	, mEnterTextTexture(enterTextTexture.get())
	, mEnterTextRect(enterTextRect)
	, mWindowWidth(windowWidth)
	, mWindowHeight(windowHeight)
{
	if (marioTextFont == nullptr)
	{
		SDL_Log("Unable to create font: %s", TTF_GetError());
	}




	if (marioTextSurface == nullptr)
	{
		SDL_Log("Unable to create surface: %s", TTF_GetError());
	}


	if (marioTextTexture == nullptr)
	{
		SDL_Log("Unable to create texture: %s", TTF_GetError());
	}
	SDL_QueryTexture(marioTextTexture.get(), nullptr, nullptr, &marioTextRect.w, &marioTextRect.h);
	marioTextRect.x = windowWidth / 2 - marioTextRect.w / 2;
	marioTextRect.y = windowHeight / 2 - marioTextRect.h / 2 - 50;


	if (enterTextFont == nullptr)
	{
		SDL_Log("Unable to create font: %s", TTF_GetError());
	}

	if (enterTextSurface == nullptr)
	{
		SDL_Log("Unable to create surface: %s", TTF_GetError());
	}


	if (enterTextTexture == nullptr)
	{
		SDL_Log("Unable to create texture: %s", TTF_GetError());
	}

	SDL_QueryTexture(enterTextTexture.get(), nullptr, nullptr, &enterTextRect.w, &enterTextRect.h);
	enterTextRect.x = windowWidth / 2 - enterTextRect.w / 2;
	enterTextRect.y = windowHeight / 2 - enterTextRect.h / 2 + marioTextRect.h;
}

RenderStartMenu::~RenderStartMenu()
{
	SDL_SetRenderDrawColor(mRenderer.get(), 0, 0, 255, 0);
	SDL_RenderClear(mRenderer.get());
	SDL_RenderCopy(mRenderer.get(), mMarioTextTexture.get(), nullptr, &mMarioTextRect);
	SDL_RenderCopy(mRenderer.get(), mEnterTextTexture.get(), nullptr, &mEnterTextRect);
	SDL_RenderPresent(mRenderer.get());
}
Main:
Код:
main
#include "RenderStartMenu.h"
enum class State
{
	StartMenuState,
	PlayGameState,
	EndMenuState
};
int main(int argc, char** argv)
{
	const int windowWidth = 1280;
	const int windowHeight = 720;

	if (SDL_Init(SDL_INIT_VIDEO) != 0)
	{
		SDL_Log("Unable to initialize SDL: %s", SDL_GetError());
		return 1;
	}
	SDLQuiter sdlQuiter(nullptr, [](void*) { SDL_Quit(); });

	if (TTF_Init() != 0)
	{
		SDL_Log("Unable to initialize TTF: %s", TTF_GetError());
		return 1;
	}
	TTFQuiter ttfQuiter(nullptr, [](void*) { TTF_Quit(); });

	SDLWindowPointer window(SDL_CreateWindow(
		"Mario by",
		SDL_WINDOWPOS_UNDEFINED,
		SDL_WINDOWPOS_UNDEFINED,
		windowWidth,
		windowHeight,
		SDL_WINDOW_OPENGL
	), SDL_DestroyWindow);
	
	if (window == nullptr)
	{
		SDL_Log("Unable to created window: %s", SDL_GetError());
		return 1;
	}
	SDLRendererPointer renderer(SDL_CreateRenderer(window.get(), -1,
		SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE), SDL_DestroyRenderer);

	if (renderer == nullptr)
	{
		SDL_Log("Failed to create renderer: %s", SDL_GetError());
		return 1;
	}

	TTFFontPointer marioTextFont(TTF_OpenFont("Resources/Fonts/Arial.TTF", 130), TTF_CloseFont);
	SDL_Color textColor = { 255, 255, 255, 255 };
	SDLSurfacePointer marioTextSurface(TTF_RenderText_Solid(marioTextFont.get(), "Mario", textColor), SDL_FreeSurface);
	SDLTexturePointer marioTextTexture(SDL_CreateTextureFromSurface(renderer.get(), marioTextSurface.get()), SDL_DestroyTexture);
	SDL_Rect marioTextRect;


	TTFFontPointer enterTextFont(TTF_OpenFont("Resources/Fonts/Arial.TTF", 30), TTF_CloseFont);
	SDLSurfacePointer enterTextSurface(TTF_RenderText_Solid(enterTextFont.get(), "Press Space to enter", textColor), SDL_FreeSurface);
	SDLTexturePointer enterTextTexture(SDL_CreateTextureFromSurface(renderer.get(), enterTextSurface.get()), SDL_DestroyTexture);
	SDL_Rect enterTextRect;

	SDL_Event event;
	State state = State::StartMenuState;
	for (bool runGame = true; runGame; )
	{
		
		
		if (state == State::StartMenuState)
		{
		/*Ось тут выклыкаю свой клас 	RenderStartMenu*/RenderStartMenu::RenderStartMenu(renderer, marioTextSurface, marioTextFont, marioTextTexture, marioTextRect,
				enterTextSurface, enterTextFont, enterTextTexture, enterTextRect, windowWidth, windowHeight);
			
		else if (state == State::PlayGameState)
		{
			
		}
		else if (state == State::EndMenuState)
		{
			
		}
	}
	return 0;
}

Последний раз редактировалось dimaSlon; 25.07.2017 в 15:50.
dimaSlon вне форума Ответить с цитированием
Старый 25.07.2017, 11:58   #3
Alex11223
Старожил
 
Аватар для Alex11223
 
Регистрация: 12.01.2011
Сообщений: 19,500
По умолчанию

Дык "крешится" или "не компилируется"?
Ушел с форума, https://www.programmersforum.rocks, alex.pantec@gmail.com, https://github.com/AlexP11223
ЛС отключены Аларом.
Alex11223 вне форума Ответить с цитированием
Старый 25.07.2017, 12:07   #4
dimaSlon
Форумчанин
 
Регистрация: 24.06.2017
Сообщений: 160
По умолчанию

Цитата:
Сообщение от Alex11223 Посмотреть сообщение
Дык "крешится" или "не компилируется"?
ой крешится
Изображения
Тип файла: png IMG_25072017_104743_0.png (7.1 Кб, 61 просмотров)
dimaSlon вне форума Ответить с цитированием
Старый 25.07.2017, 12:08   #5
dimaSlon
Форумчанин
 
Регистрация: 24.06.2017
Сообщений: 160
По умолчанию

дебажился
Изображения
Тип файла: jpg IMG_25072017_105330_0.jpg (76.9 Кб, 127 просмотров)
dimaSlon вне форума Ответить с цитированием
Старый 25.07.2017, 12:52   #6
AlexMas
Пользователь
 
Аватар для AlexMas
 
Регистрация: 30.05.2012
Сообщений: 69
По умолчанию

Объект класса не пробовали создавать?
Код:
RenderStartMenu* rsm;
rsm = new RenderStartMenu(renderer, marioTextSurface, marioTextFont, marioTextTexture, marioTextRect, enterTextSurface, enterTextFont, enterTextTexture, enterTextRect, windowWidth, windowHeight);
или
Код:
RenderStartMenu rsm(renderer, marioTextSurface, marioTextFont, marioTextTexture, marioTextRect, enterTextSurface, enterTextFont, enterTextTexture, enterTextRect, windowWidth, windowHeight);
AlexMas вне форума Ответить с цитированием
Старый 25.07.2017, 13:03   #7
dimaSlon
Форумчанин
 
Регистрация: 24.06.2017
Сообщений: 160
По умолчанию

Цитата:
Сообщение от AlexMas Посмотреть сообщение
Объект класса не пробовали создавать?
Код:
RenderStartMenu* rsm;
rsm = new RenderStartMenu(renderer, marioTextSurface, marioTextFont, marioTextTexture, marioTextRect, enterTextSurface, enterTextFont, enterTextTexture, enterTextRect, windowWidth, windowHeight);
или
Код:
RenderStartMenu rsm(renderer, marioTextSurface, marioTextFont, marioTextTexture, marioTextRect, enterTextSurface, enterTextFont, enterTextTexture, enterTextRect, windowWidth, windowHeight);
пробовал
Severity Code Description Project File Line Suppression State
Error (active) expected a ';' Mario d:\Git\Mario\Main.cpp 258
Severity Code Description Project File Line Suppression State
Error C3861 'renderStartMenu': identifier not found Mario d:\git\mario\main.cpp 258
Код:
RenderStartMenu renderStartMenu(renderer, marioTextSurface, marioTextFont, marioTextTexture, marioTextRect,
				enterTextSurface, enterTextFont, enterTextTexture, enterTextRect, windowWidth, windowHeight);
dimaSlon вне форума Ответить с цитированием
Старый 25.07.2017, 14:08   #8
dimaSlon
Форумчанин
 
Регистрация: 24.06.2017
Сообщений: 160
По умолчанию

Цитата:
Сообщение от Alex11223 Посмотреть сообщение
Дык "крешится" или "не компилируется"?
Так ж можно перадавать конструктор как я передаю?
dimaSlon вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
[РЕШЕНО] Не компилируется программа. kyle16 Паскаль, Turbo Pascal, PascalABC.NET 2 28.02.2016 14:31
Программа компилируется, но не отображается volchek3 Общие вопросы Delphi 2 09.07.2012 01:48
Программа компилируется, но не работает maziLa Assembler - Ассемблер (FASM, MASM, WASM, NASM, GoASM, Gas, RosAsm, HLA) и не рекомендуем TASM 6 17.07.2009 11:24
Не компилируется программа kiloruble Общие вопросы C/C++ 11 17.11.2008 20:51
Не компилируется программа VladimirVB Assembler - Ассемблер (FASM, MASM, WASM, NASM, GoASM, Gas, RosAsm, HLA) и не рекомендуем TASM 4 14.10.2008 23:22