Sign in to follow this  

Cannot declare pointer "to "void" member

This topic is 2052 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, im trying to get a TGA image into my MD3 loader, but i cant seem to get this piece of code to work,
in my GameAsset.cpp i have a make_tga method and a make_texture method
Here is my GameAsset.h
[CODE]
/*
* GameObject.h
*
* Created on: 03-Mar-2009
* Author: balor
*/
#include <GL/glew.h>
#include <GL/gl.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <fstream>
#include "vectormath/scalar/cpp/vectormath_aos.h"
#include "Camera.h"
#include "BoundingBox.h"
using namespace std;
using namespace Vectormath::Aos;
#ifndef GAMEASSET_H_
#define GAMEASSET_H_
class GameAsset {
public:
GameAsset();
GameAsset(const string & v_shader, const string & f_shader);
virtual ~GameAsset();
bool collidesWith(GameAsset & a);
virtual void draw();
virtual void update()=0;
void updateVertexBuffer();
void *read_tga(const char *filename, int *width, int *height);
protected:
/* functions */
int make_resources();
GLuint makeTexture(const char * filename,int width,int height);
GLchar* shader_file_contents(const string &filename, GLint * length);
GLuint make_buffer(GLenum target, const void *buffer_data, GLsizei buffer_size);
GLuint make_shader(GLenum type, const char *filename);
GLuint make_program(GLuint vertex_shader, GLuint fragment_shader);
/* For keeping track of OpenGL VBOs */
GLuint vertex_buffer, element_buffer;
GLuint vertex_shader, fragment_shader, program;
GLint position_attrib;
GLint mv_matrix_uniform;
GLfloat * g_vertex_buffer_data;
GLushort * g_element_buffer_data;
Matrix4 mv_matrix;

// How many vertices/triangles in this model
int num_vertices;
int num_triangles;
BoundingBox * bbox;
private:
void common_init(); // because we don't have delegating constructors yet (http://gcc.gnu.org/projects/cxx0x.html)
string v_shader;
string f_shader;
};
#endif /* GAMEASSET_H_ */
[/CODE]


And here is my GameAsset.cpp file
[CODE]
/*
* GameObject.cpp
*
* Created on: 03-Mar-2009
* Author: balor
*/
#include "GameAsset.h"
void GameAsset::common_init() {
mv_matrix = Matrix4::identity();
bbox = new BoundingBox(Point3(0,0,0), 1.0, 1.0, 1.0); // unit cube
}
GameAsset::GameAsset() {
common_init();
this->v_shader = "shaders/hello-gl.v.glsl";
this->f_shader = "shaders/hello-gl.f.glsl";
}
GameAsset::GameAsset(const string & v_shader, const string & f_shader) {
common_init();
this->v_shader = v_shader;
this->f_shader = f_shader;
}
GameAsset::~GameAsset() {
// TODO Auto-generated destructor stub
}
bool GameAsset::collidesWith(GameAsset & a ) {
return bbox->collidesWith((*a.bbox));
}
void GameAsset::draw() {
glUseProgram(program);
mv_matrix = Camera::getInstance().getCameraM() * mv_matrix;
// horribe unpacking
GLfloat foo [16] = {
mv_matrix.getElem(0,0), mv_matrix.getElem(0,1), mv_matrix.getElem(0,2), mv_matrix.getElem(0,3),
mv_matrix.getElem(1,0), mv_matrix.getElem(1,1), mv_matrix.getElem(1,2), mv_matrix.getElem(1,3),
mv_matrix.getElem(2,0), mv_matrix.getElem(2,1), mv_matrix.getElem(2,2), mv_matrix.getElem(2,3),
mv_matrix.getElem(3,0), mv_matrix.getElem(3,1), mv_matrix.getElem(3,2), mv_matrix.getElem(3,3)
};
glUniformMatrix4fv(mv_matrix_uniform, 1, false, foo);
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
glVertexAttribPointer(
position_attrib, /* attribute */
3, /* size */
GL_FLOAT, /* type */
GL_FALSE, /* normalized? */
0, /* stride */
(void*)0 /* array buffer offset */
);
glEnableVertexAttribArray(position_attrib);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, element_buffer);
glDrawElements(
GL_TRIANGLES,
3 * this->num_triangles,
GL_UNSIGNED_SHORT,
(GLvoid*) 0
);

glDisableVertexAttribArray(position_attrib);
}
/*
* Functions for general purpose stuff
*/
GLchar * GameAsset::shader_file_contents(const string &filename, GLint * length)
{
ifstream input_file;
input_file.open(filename.c_str(), ios::in);
input_file.seekg(0, ios::end); // go to the end of the file
*length = input_file.tellg(); // get length of the file
input_file.seekg(0, ios::beg); // go to beginning of the file
GLchar * buffer = new GLchar[(*length)+1];
input_file.read(buffer, *length);
buffer[(*length)+1]='\0'; // Ensure null terminated
input_file.close();
return buffer;
}
/*
* Functions for creating OpenGL objects:
*/
GLuint GameAsset::make_buffer(
GLenum target,
const void *buffer_data,
GLsizei buffer_size
) {
GLuint buffer;
glGenBuffers(1, &buffer);
glBindBuffer(target, buffer);
glBufferData(target, buffer_size, buffer_data, GL_STATIC_DRAW);
return buffer;
}
GLuint GameAsset::make_shader(GLenum type, const char *filename)
{
GLint length;
GLchar *source = shader_file_contents(filename, &length);
GLuint shader;
GLint shader_ok;
if (!source)
return 0;
shader = glCreateShader(type);
glShaderSource(shader, 1, (const GLchar**)&source, &length);
delete(source);
glCompileShader(shader);
glGetShaderiv(shader, GL_COMPILE_STATUS, &shader_ok);
if (!shader_ok) {
cerr << "Failed to compile" << filename << " with error code " << shader_ok << endl;
glDeleteShader(shader);
return 0;
}
return shader;
}
GLuint GameAsset::make_program(GLuint vertex_shader, GLuint fragment_shader)
{
GLint program_ok;
GLuint program = glCreateProgram();
glAttachShader(program, vertex_shader);
glAttachShader(program, fragment_shader);
glLinkProgram(program);
glGetProgramiv(program, GL_LINK_STATUS, &program_ok);
if (!program_ok) {
cerr<< "Failed to link shader program:" << endl;
glDeleteProgram(program);
return 0;
}
return program;
}
/*
* Load and create all of our resources:
*/
int GameAsset::make_resources(void)
{
vertex_buffer = make_buffer(
GL_ARRAY_BUFFER,
g_vertex_buffer_data,
3 * sizeof(GLfloat) * this->num_vertices
);
element_buffer = make_buffer(
GL_ELEMENT_ARRAY_BUFFER,
g_element_buffer_data,
3 * sizeof(GLushort) * this->num_triangles
);
vertex_shader = make_shader(
GL_VERTEX_SHADER,
this->v_shader.c_str()
);
if (vertex_shader == 0)
return 0;
fragment_shader = make_shader(
GL_FRAGMENT_SHADER,
this->f_shader.c_str()
);
if (fragment_shader == 0)
return 0;


program = make_program(vertex_shader, fragment_shader);
if (program == 0)
return 0;
position_attrib = glGetAttribLocation(program, "position");
mv_matrix_uniform = glGetUniformLocation(program, "mv_matrix");
return 1;
}
void GameAsset::updateVertexBuffer()
{
vertex_buffer = make_buffer(
GL_ARRAY_BUFFER,
g_vertex_buffer_data,
3 * sizeof(GLfloat) * this->num_vertices
);
}
/*
* TGA READER
*/
static short file_short(unsigned char *bytes)
{
return bytes[0] | ((char)bytes[1] << 8);
}
GLuint GameAsset::makeTexture(const char * filename,int width,int height)
{
GLuint texture;
void *pixels = read_tga(filename, &width, &height);
if(!pixels)
{
return 0;
}
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(
GL_TEXTURE_2D, 0,
GL_RGB8,
width, height, 0,
GL_BGR, GL_UNSIGNED_BYTE,
pixels
);
free(pixels);
return texture;
}
void GameAsset::*read_tga(const char *filename, int *width, int *height)
{
struct tga_header {
char id_length;
char color_map_type;
char data_type_code;
unsigned char color_map_origin[2];
unsigned char color_map_length[2];
char color_map_depth;
unsigned char x_origin[2];
unsigned char y_origin[2];
unsigned char width[2];
unsigned char height[2];
char bits_per_pixel;
char image_descriptor;
} header;
int i, color_map_size, pixels_size;
FILE *f;
size_t read;
void *pixels;
f = fopen(filename, "rb");
if (!f) {
fprintf(stderr, "Unable to open %s for reading\n", filename);
return NULL;
}
read = fread(&header, 1, sizeof(header), f);
if (read != sizeof(header)) {
fprintf(stderr, "%s has incomplete tga header\n", filename);
fclose(f);
return NULL;
}
if (header.data_type_code != 2) {
fprintf(stderr, "%s is not an uncompressed RGB tga file\n", filename);
fclose(f);
return NULL;
}
if (header.bits_per_pixel != 24) {
fprintf(stderr, "%s is not a 24-bit uncompressed RGB tga file\n", filename);
fclose(f);
return NULL;
}
for (i = 0; i < header.id_length; ++i)
if (getc(f) == EOF) {
fprintf(stderr, "%s has incomplete id string\n", filename);
fclose(f);
return NULL;
}
color_map_size = file_short(header.color_map_length) * (header.color_map_depth/8);
for (i = 0; i < color_map_size; ++i)
if (getc(f) == EOF) {
fprintf(stderr, "%s has incomplete color map\n", filename);
fclose(f);
return NULL;
}
*width = file_short(header.width); *height = file_short(header.height);
pixels_size = *width * *height * (header.bits_per_pixel/8);
pixels = malloc(pixels_size);
read = fread(pixels, 1, pixels_size, f);
if (read != pixels_size) {
fprintf(stderr, "%s has incomplete image\n", filename);
fclose(f);
free(pixels);
return NULL;
}
return pixels;
}
[/CODE]

This is the line void GameAsset::*read_tga(const char *filename, int *width, int *height) that displays
cannot declare pointer to "void" member, anyone know how i can fix this?

im trying to read in a TGA file so i can texture it around the MD3 model

Cheers Canvas

Share this post


Link to post
Share on other sites
This line:
[code]
void GameAsset::*read_tga(const char *filename, int *width, int *height)
[/code]
should be:
[code]
void * GameAsset::read_tga(const char *filename, int *width, int *height)
[/code]

Share this post


Link to post
Share on other sites

This topic is 2052 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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