Sign in to follow this  
Canvas

No matching function problem

Recommended Posts

Hey guys, ive been posting alot about the MD3loader but i think i have finally got it...i hope, but i seem to be having a very small problem
Im getting a no matching function problem in my main,

Ive got a constructor that takes in a vector of Md3Asset(s) and a const string for the texture name, now when i call it i get the no matching function, Im going to give you all the code for Main.cpp, DrawMd3.cpp and DrawMd3.h

Main.cpp
[CODE]
#define GLEW_STATIC // Easier debugging
#include <GL/glew.h>
#include <GL/gl.h>
#include <SDL/SDL.h>
#include <iostream>
#include <fstream>
#include <vector>
#include "GameAsset.h"
#include "Md2Asset.h"
#include "TriangularPyramidAsset.h"
#include "BallisticInterpolator.h"
#include "Camera.h"
#include "Md3Asset.h"
#include "DrawMd3.h"
using namespace std;
#define RUN_GRAPHICS_DISPLAY 0x00;
//string filename = "data/sarge/head.md3";
Md3Asset * goLower;
Md3Asset * goUpper;
Md3Asset * goHead;
DrawMd3 *drawModel;
vector<GameAsset *> model;
/*
* SDL timers run in separate threads. In the timer thread
* push an event onto the event queue. This event signifies
* to call display() from the thread in which the OpenGL
* context was created.
*/
Uint32 display(Uint32 interval, void *param) {
SDL_Event event;
event.type = SDL_USEREVENT;
event.user.code = RUN_GRAPHICS_DISPLAY;
event.user.data1 = 0;
event.user.data2 = 0;
SDL_PushEvent(&event);
return interval;
}
void display() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
// This O(n + n^2 + n) sequence of loops is written for clarity,
// not efficiency
/*for(std::vector<GameAsset *>::iterator it = assets.begin(); it != assets.end(); ++it) {
(*it)->update();
}
for(std::vector<GameAsset *>::iterator i = assets.begin(); i != assets.end(); ++i) {
for(std::vector<GameAsset *>::iterator j = assets.begin(); j != assets.end(); ++j) {
if(*i != *j && (*i)->collidesWith(**j)) {
cout << "We have a collision" << endl;
}
}
}
for(std::vector<GameAsset *>::iterator it = assets.begin(); it != assets.end(); ++it) {
(*it)->draw();
}*/

//My METHODS
drawModel->draw();
//END OF MY METHODS
// Don't forget to swap the buffers
SDL_GL_SwapBuffers();
}
int main(int argc, char ** argv) {
//Model information
string headFilename = argv[1];
headFilename += "data/sarge/head.md3";
string upperFilename = argv[1];
upperFilename += "data/sarge/upper.md3";
string lowerFilename = argv[1];
lowerFilename += "data/sarge/lower.md3";
string textureFilename = argv[1];
textureFilename += argv[2];
//End of Model information
SDL_Surface * surf;
Uint32 width = 640;
Uint32 height = 480;
Uint32 colour_depth = 16; // in bits
Uint32 delay = 1000/60; // in milliseconds
// Initialise SDL - when using C/C++ it's common to have to
// initialise libraries by calling a function within them.
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER)<0) {
cout << "Failed to initialise SDL: " << SDL_GetError() << endl;
SDL_Quit();
}
// When we close a window quit the SDL application
atexit(SDL_Quit);
// Create a new window with an OpenGL surface
if (!(surf = SDL_SetVideoMode(width, height, colour_depth, SDL_OPENGL))) {
cout << "Failed to initialise video mode: " << SDL_GetError() << endl;
SDL_Quit();
}
// Initialise GLEW - an easy way to ensure OpenGl 2.0+
// The *must* be done after we have set the video mode - otherwise we have no OpenGL context.
glewInit();
if (!glewIsSupported("GL_VERSION_2_0")) {
cerr<< "OpenGL 2.0 not available" << endl;
return 1;
}
Vector3 launch(5.0f, 70.7f, 0.0f);
BallisticInterpolator * li = new BallisticInterpolator(launch, 60);
//TriangularPyramidAsset * p = new TriangularPyramidAsset(0, 0, 3);
//p->setInterpolator(li);
//Md3Asset * p = new Md3Asset(filename);
//assets.push_back(p);
goLower = new Md3Asset(lowerFilename);
goUpper = new Md3Asset(upperFilename);
goHead = new Md3Asset(headFilename);
model.push_back(goLower);
model.push_back(goUpper);
model.push_back(goHead);
drawModel = new DrawMd3(model, textureFilename);
// Call the function "display" every delay milliseconds
SDL_AddTimer(delay, display, NULL);
// Add the main event loop
SDL_Event event;
while (SDL_WaitEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
SDL_Quit();
break;
case SDL_USEREVENT:
display();
break;
case SDL_KEYUP:
Camera::getInstance().setCamera(Matrix4::identity());
break;
case SDL_KEYDOWN:
Matrix4 camera = Camera::getInstance().getCameraM();
switch(event.key.keysym.sym){
case SDLK_LEFT:
Camera::getInstance().setCamera((camera * Matrix4::rotationY(5.0/180.0)));
break;
case SDLK_RIGHT:
Camera::getInstance().setCamera(camera * Matrix4::rotationY(-5.0/180.0) );
break;
case SDLK_UP:
Camera::getInstance().setCamera(camera * Matrix4::translation(Vector3(0.0, 0.0, -1.0)) );
break;
case SDLK_DOWN:
Camera::getInstance().setCamera(camera * Matrix4::translation(Vector3(0.0, 0.0, 1.0)) );
break;
default:
break;
}
break;
}
}
}
[/CODE]

DrawMd3.h code
//This is used to create all the vertices and what not to be displayed
[CODE]
/*
* DrawMd3.h
*
* Created on: Apr 27, 2012
* Author: ben
*/
#ifndef DRAWMD3_H_
#define DRAWMD3_H_
#include <GL/glew.h>
#include <GL/gl.h>
#include <SDL/SDL.h>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "Md3Asset.h"
#include "GameAsset.h"
class DrawMd3 {
public:
DrawMd3(vector<Md3Asset *> mod, const string &texture);
void draw();
GLchar* shaderFileContent(const string &filename, GLint * length);
GLuint makeBuffer(GLenum target, const void *bufferData, GLsizei bufferSize);
GLuint makeShader(GLenum type, const char *filename);
GLuint makeProgram(GLuint vertexShader, GLuint fragmentShader);
void setVertex(int pos,float vertex);
float rtnVertex(int vertex);
virtual ~DrawMd3();
private:
GLuint texID;
GLuint vertex_buffer, element_buffer;
GLuint vertex_shader, fragment_shader, program;
GLint pos;
GLint rotateX;
int total_triangles;
int total_vertices;
GLfloat * vertex_bufferData;
GLushort * element_bufferData;
GLfloat rotate_xAxis;
GLfloat * texCoords_bufferData;
void createBuffers(vector<Md3Asset *> mod);
int makeResources();
};
#endif /* DRAWMD3_H_ */
[/CODE]

DrawMd3.cpp code
//This is used to create all the vertices and what not
[CODE]
/*
* DrawMd3.cpp
*
* Created on: Apr 27, 2012
* Author: ben
*/
#include "DrawMd3.h"
DrawMd3::~DrawMd3() {
// TODO: clean up
}

DrawMd3::DrawMd3(vector<Md3Asset *> mod, const string &texture)
{
//Gets information from the first frame only
texCoords_bufferData = new GLfloat
[2 * (mod.at(0)->rtn_numVertices(-1) +
mod.at(1)->rtn_numVertices(-1) +
mod.at(2)->rtn_numVertices(-1))];
rotate_xAxis = 0;
createBuffers(mod);
if(0 == makeResources())
{
cout << "Error createing MD3 model asset!" << endl;
}
}
float DrawMd3::rtnVertex(int vertex)
{
return vertex_bufferData[vertex];
}
void DrawMd3::setVertex(int pos,float vertex)
{
vertex_bufferData[pos] = vertex;
}
void DrawMd3::createBuffers(vector<Md3Asset *> mod)
{
total_triangles = mod.at(0)->rtn_numTriangles(-1) +
mod.at(1)->rtn_numTriangles(-1) +
mod.at(2)->rtn_numTriangles(-1);
total_vertices = mod.at(0)->rtn_numVertices(-1) +
mod.at(1)->rtn_numVertices(-1) +
mod.at(2)->rtn_numVertices(-1);
element_bufferData = new GLushort[total_triangles * 3];
vertex_bufferData = new GLfloat[total_vertices * 3];
//texCoords_array
//[2 * (mod.at(0)->rtn_numVertices(0) +
//mod.at(1)->rtn_numVertices(0) +
//mod.at(2)->rtn_numVertices(0))];
int b = 0, c = 0,d = 0, base = 0;
for (int k = 0; k < 3; k++)
{
for (int i = 0; i < mod.at(k)->rtn_numSurfaces(); i++)
{
for(int j = 0; j < mod.at(k)->rtn_numTriangles(i); j++)
{
this->element_bufferData[c++] = mod.at(k)->rtn_triPoint(i,j,0) + base;
this->element_bufferData[c++] = mod.at(k)->rtn_triPoint(i,j,1) + base;
this->element_bufferData[c++] = mod.at(k)->rtn_triPoint(i,j,2) + base;
}//End of for loop j
base += mod.at(k)->rtn_numVertices(i);
//Case statement to indicate which part of the model we are loading
switch(k)
{
case 0 : // Lower.MD3
for(int j = 0; j < mod.at(k)->rtn_numVertices(i); j++)
{
this->vertex_bufferData[b++] = (mod.at(k)->rtn_vertex(i,j,0) / 64.0);
this->vertex_bufferData[b++] = (mod.at(k)->rtn_vertex(i,j,1) / 64.0);
this->vertex_bufferData[b++] = (mod.at(k)->rtn_vertex(i,j,2) / 64.0);
cout << "Legs: " << i << ":" << j << endl;
texCoords_bufferData[d++] = mod.at(k)->rtn_texCoords(i,j,0);
texCoords_bufferData[d++] = mod.at(k)->rtn_texCoords(i,j,1);
}//End of for loop j
break;
case 1 : // Upper.MD3
for(int j = 0; j < mod.at(k)->rtn_numVertices(i); j++)
{
this->vertex_bufferData[b++] = mod.at(0)->rtn_tagOrigin(0,0,0) +
(mod.at(k)->rtn_vertex(i,j,0) / 64.0);
this->vertex_bufferData[b++] = mod.at(0)->rtn_tagOrigin(0,0,1) +
(mod.at(k)->rtn_vertex(i,j,1) / 64.0);
this->vertex_bufferData[b++] = mod.at(0)->rtn_tagOrigin(0,0,2) +
(mod.at(k)->rtn_vertex(i,j,2) / 64.0);
texCoords_bufferData[d++] = mod.at(k)->rtn_texCoords(i,j,0);
texCoords_bufferData[d++] = mod.at(k)->rtn_texCoords(i,j,1);
cout << "Upper: " << i << ":" << j << endl;
}//End of for loop j
break;
case 2 : //Head.MD3
for(int j = 0; j < mod.at(k)->rtn_numVertices(i); j++)
{
this->vertex_bufferData[b++] = mod.at(0)->rtn_tagOrigin(0,0,0) +
mod.at(1)->rtn_tagOrigin(0,0,0) +
(mod.at(k)->rtn_vertex(i,j,0) / 64.0);
this->vertex_bufferData[b++] = mod.at(0)->rtn_tagOrigin(0,0,1) +
mod.at(1)->rtn_tagOrigin(0,0,1) +
(mod.at(k)->rtn_vertex(i,j,1) / 64.0);
this->vertex_bufferData[b++] = mod.at(0)->rtn_tagOrigin(0,0,2) +
mod.at(1)->rtn_tagOrigin(0,0,2) +
(mod.at(k)->rtn_vertex(i,j,2) / 64.0);
cout << "Head: " << i << ":" << j << endl;
texCoords_bufferData[d++] = mod.at(k)->rtn_texCoords(i,j,0);
texCoords_bufferData[d++] = mod.at(k)->rtn_texCoords(i,j,1);
}//End of for loop j
break;
}//End of switch statement
}//End of for loop i
}//End of k for loop
cout << "Finished making buffers" << endl;
}
void DrawMd3::draw()
{
glUseProgram(program);
glUniform1f(rotateX, rotate_xAxis++);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texID);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
glVertexAttribPointer
(
pos, //Position
3, //Size
GL_FLOAT, //Type
GL_FALSE, //Normal
0, //Stride
(void*)0 //Array buffer offset
);
glEnableVertexAttribArray(pos);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, element_buffer);
glDrawElements
(
GL_TRIANGLES,
3 * total_triangles,
GL_UNSIGNED_SHORT,
(GLvoid*) 0
);
glDisableVertexAttribArray(pos);
}
GLuint DrawMd3::makeBuffer(GLenum target, const void *bufferData, GLsizei bufferSize)
{
cout << "Make buffer" << endl;
GLuint buffer;
glGenBuffers(1, &buffer);
cout << "Buffer made" << endl;
glBindBuffer(target, buffer);
glBufferData(target, bufferSize, bufferData, GL_STATIC_DRAW);
return buffer;
}
GLchar* DrawMd3::shaderFileContent(const string &filename, GLint * length)
{
ifstream file;
file.open(filename.c_str(), ios::in);
file.seekg(0, ios::end); //Go to end of file
*length = file.tellg(); //Get length of file
file.seekg(0, ios::beg); //Go to beginning of file
GLchar * buffer = new GLchar[(*length)+1];
file.read(buffer, *length);
buffer[(*length)+1]='\0'; //Ensure null terminated
file.close();
return buffer;
}
GLuint DrawMd3::makeShader(GLenum type, const char *filename)
{
cout << "Make shader" << endl;
GLint length;
GLchar *source = shaderFileContent(filename, &length);
GLuint shader;
GLint shaderOK;
if(!source)
{
return 0;
}
shader = glCreateShader(type);
glShaderSource(shader, 1, (const GLchar**)&source, &length);
delete(source);
glCompileShader(shader);
glGetShaderiv(shader, GL_COMPILE_STATUS, &shaderOK);
if (!shaderOK)
{
cout << "Failed to compile:" << filename << ". With error code:" << shaderOK << endl;
glDeleteShader(shader);
return 0;
}
return shader;
}
GLuint DrawMd3::makeProgram(GLuint vertexShader, GLuint fragmentShader)
{
cout << "Making program" << endl;
GLint programOK;
GLuint program = glCreateProgram();
glAttachShader(program, vertexShader);
glAttachShader(program, fragmentShader);
glLinkProgram(program);
glGetProgramiv(program, GL_LINK_STATUS, &programOK);
if (!programOK)
{
cout << "Failed to link a shader program." << endl;
glDeleteProgram(program);
return 0;
}
return program;
}

//Load and create all of our resources:
int DrawMd3::makeResources(void)
{
vertex_buffer = makeBuffer
(
GL_ARRAY_BUFFER,
vertex_bufferData,
3 * sizeof(GLfloat) * total_vertices
);
element_buffer = makeBuffer
(
GL_ELEMENT_ARRAY_BUFFER,
element_bufferData,
3 * sizeof(GLushort) * total_triangles
);
vertex_shader = makeShader
(
GL_VERTEX_SHADER,
"src/hello-gl.v.glsl"
);
if (vertex_shader == 0)
{
return 0;
}
fragment_shader = makeShader
(
GL_FRAGMENT_SHADER,
"src/hello-gl.f.glsl"
);
if (fragment_shader == 0)
{
return 0;
}
program = makeProgram(vertex_shader, fragment_shader);
if (program == 0)
{
return 0;
}
pos = glGetAttribLocation(program, "Position");
rotateX = glGetUniformLocation(program, "Rotate X Axis");
}
[/CODE]

Any idea why im getting that error?

Canvas

!!!I have just changed my vector of GameAssets to be a vector of Md3Assets and it compiles. but when i run i get this error


terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct null not valid

I have just fixed that error, but now when my code compiles it opens a window for abit, it shows most of the debug then i get this error


Legs: 0:345
Legs: 0:346
Legs: 0:347
Legs: 0:348
Legs: 0:349
Legs: 0:350
Legs: 0:351
Legs: 0:352terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check

Legs: 0:353
Legs: 0:354
Legs: 0:355
Legs: 0:356
Legs: 0:357
Legs: 0:358
Legs: 0:359
Legs: 0:360
Legs: 0:361
Legs: 0:362

after more work i have now got the error at the end of the legs


File loaded
HERE
terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check

now i did alittle bit of debugging,

Here is my constructor in DrawMd3.cpp
[CODE]
DrawMd3::DrawMd3(vector<Md3Asset *> mod, const string &texture)
{
cout << "HERE" << endl;
//Gets information from the first frame only
texCoords_bufferData = new GLfloat
[2 * (mod.at(0)->rtn_numVertices(-1) +
mod.at(1)->rtn_numVertices(-1) +
mod.at(2)->rtn_numVertices(-1))];
cout << "HERE" << endl;
rotate_xAxis = 0;
createBuffers(mod);
if(0 == makeResources())
{
cout << "Error createing MD3 model asset!" << endl;
}

}
[/CODE]

after it creates the texCoords_bufferData thats when it crashes, it doesnt get to the next HERE, anyone see the problem? Edited by Canvas

Share this post


Link to post
Share on other sites
The exception is already telling you exactly what's happening. Don't access a vector with an invalid index. Don't blindly rely on it containing at least 3 elements. When debugging, step _into_ that call, not _over_ it to see which of those calls fails.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this