编译出错,请高手指点:error C2143: syntax error : missing ';' before 'string'

jusen67 2009-04-07 05:41:24
代码如下:
编译时出错:
Compiling...
Texture.cpp
d:\program files\microsoft visual studio\vc98\include\stdio.h(36) : error C2143: syntax error : missing ';' before 'string'
d:\program files\microsoft visual studio\vc98\include\stdio.h(36) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

Texture.obj - 2 error(s), 0 warning(s)

#include"Texture.h"

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

Texture::Texture
{

}

Texture::~Texture
{

}

void Texture::Load(char *name)
{
texturename = strlwr(strdup(name));

if (strstr(texturename, "\"))
texturename = strtok(texturename, "\");

if(strstr(texturename, ".bmp"))
LoadBMP(texturename);
}

void Texture::LoadFromResource(char *name)
{
texturename = strlwr(strdup(name));

if(strstr(texturename, ".bmp"))
LoadBMPResource(name);
}

void Texture::Use()
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,texture[0]);
}

void Texture::LoadBMP(char *name)
{
AUX_RGBImageRec *TextureImage[1];

memset(TextureImage,0,sizeof(void *)*1);

TextureImage[0] = auxDIBImageLoad(name);

width = TextureImage[0]->sizeX;
height = TextureImage[0]->sizeY;

glGenTextures(1, &texture[0]);

glBindTexture(GL_TEXTURE_2D, texture[0]);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

if (TextureImage[0])
{
if (TextureImage[0]->data)
{
free(TextureImage[0]->data);
}
free(TextureImage[0]);
}
}

void Texture::LoadBMPResource(char *name)
{
HRSRC hrsrc = FindResource(0, name, RT_BITMAP);
if (hrsrc==0)
return;

HGLOBAL resource = LoadResource(0, hrsrc);
if (resource==0)
return;

void *buffer = LockResource(resource);

BITMAP *bmp = (BITMAP*)buffer;

width = bmp->bmWidth;
height = bmp->bmHeight;

unsigned char *ptr = (unsigned char *)buffer+sizeof(BITMAPINFO)+2;
unsigned char temp;

for (int i = 0; i < width*height; i++)
{
temp = ptr[i*3];
ptr[i*3] = ptr[i*3+2];
ptr[i*3+2] = temp;
}

glGenTextures(1, &texture[0]);

glBindTexture(GL_TEXTURE_2D, texture[0]);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, (unsigned char *)buffer+sizeof(BITMAPINFO)+2);

free(buffer);
free(bmp);
}

void Texture::BuildColorTexture(unsigned char r,unsigned char g,unsigned char b)
{
unsigned char data[12];

for(int i = 0; i < 12; i += 3)
{
data[i] = r;
data[i+1] = g;
data[i+2] = b;
}

glGenTextures(1, &texture[0]);

glBindTexture(GL_TEXTURE_2D, texture[0]);

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 2, 2, GL_RGB, GL_UNSIGNED_BYTE, data);
}

请高手指点下,小弟不胜感激!!!
...全文
881 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
jusen67 2009-04-08
  • 打赏
  • 举报
回复
谢谢了。。。!
heartofmaple 2009-04-07
  • 打赏
  • 举报
回复
类声明最后边的"}"要加“;”,另Load函数中的"\"要改为"\\".
jusen67 2009-04-07
  • 打赏
  • 举报
回复
这是Texture.h:

#ifndef Texture_H
#define Texture_H

#include<windows.h>
#include<gl\gl.h>
#include<gl\glu.h>
#include<gl\glaux.h>

class Texture
{
public:
char *texturename; // The textures name
unsigned int texture[1]; // OpenGL's number for the texture
int width; // Texture's width
int height; // Texture's height
void Use(); // Binds the texture for use
void BuildColorTexture(unsigned char r, unsigned char g, unsigned char b); // Sometimes we want a texture of uniform color
void LoadBMPResource(char *name); // Load a bitmap from the resources
void LoadFromResource(char *name); // Load the texture from a resource
void LoadBMP(char *name); // Loads a bitmap file
void Load(char *name); // Load the texture
Texture(); // Constructor
virtual ~Texture(); // Destructor
}

#endif Texture_H
jusen67 2009-04-07
  • 打赏
  • 举报
回复
不行啊 还是那样 括号好着呢~~~
wutaihua 2009-04-07
  • 打赏
  • 举报
回复
还有一种可能性,就是你的头文件中,括号不对应。Texture.h中
vcPlayer 2009-04-07
  • 打赏
  • 举报
回复
在你的包含语句后加上:

using namespace std;
wutaihua 2009-04-07
  • 打赏
  • 举报
回复
先帮你整理下代码

#include"Texture.h"

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

Texture::Texture
{

}

Texture::~Texture
{

}

void Texture::Load(char *name)
{
texturename = strlwr(strdup(name));

if (strstr(texturename, "\"))
texturename = strtok(texturename, "\");

if(strstr(texturename, ".bmp"))
LoadBMP(texturename);
}

void Texture::LoadFromResource(char *name)
{
texturename = strlwr(strdup(name));

if(strstr(texturename, ".bmp"))
LoadBMPResource(name);
}

void Texture::Use()
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,texture[0]);
}

void Texture::LoadBMP(char *name)
{
AUX_RGBImageRec *TextureImage[1];

memset(TextureImage,0,sizeof(void *)*1);

TextureImage[0] = auxDIBImageLoad(name);

width = TextureImage[0]->sizeX;
height = TextureImage[0]->sizeY;

glGenTextures(1, &texture[0]);

glBindTexture(GL_TEXTURE_2D, texture[0]);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

if (TextureImage[0])
{
if (TextureImage[0]->data)
{
free(TextureImage[0]->data);
}
free(TextureImage[0]);
}
}

void Texture::LoadBMPResource(char *name)
{
HRSRC hrsrc = FindResource(0, name, RT_BITMAP);
if (hrsrc==0)
return;

HGLOBAL resource = LoadResource(0, hrsrc);
if (resource==0)
return;

void *buffer = LockResource(resource);

BITMAP *bmp = (BITMAP*)buffer;

width = bmp->bmWidth;
height = bmp->bmHeight;

unsigned char *ptr = (unsigned char *)buffer+sizeof(BITMAPINFO)+2;
unsigned char temp;

for (int i = 0; i < width*height; i++)
{
temp = ptr[i*3];
ptr[i*3] = ptr[i*3+2];
ptr[i*3+2] = temp;
}

glGenTextures(1, &texture[0]);

glBindTexture(GL_TEXTURE_2D, texture[0]);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, (unsigned char *)buffer+sizeof(BITMAPINFO)+2);

free(buffer);
free(bmp);
}

void Texture::BuildColorTexture(unsigned char r,unsigned char g,unsigned char b)
{
unsigned char data[12];

for(int i = 0; i < 12; i += 3)
{
data[i] = r;
data[i+1] = g;
data[i+2] = b;
}

glGenTextures(1, &texture[0]);

glBindTexture(GL_TEXTURE_2D, texture[0]);

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 2, 2, GL_RGB, GL_UNSIGNED_BYTE, data);
}

19,469

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧