OpenGL波浪仿真的问题

dontmakefunofme 2008-03-31 09:54:12
回调函数display循环
刚开始的时候很快
后来就卡了
提示虚拟内存太低(我的内存是1g的。cpu奔4 3.0的)
后来波浪就没有颜色了
变成纯白的,并且纹理贴图也没有了
display中也有清除颜色和深度缓存的命令
不知道问题出在哪里
...全文
170 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
dontmakefunofme 2008-04-03
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 vrace 的回复:]
每画一帧你都生成了一次材质,你觉得呢。。。


C/C++ code
int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
int x, y;
float float_x, L;
L=80.0;

glClear(GL_COLOR_BUFFER_BIT ¦ GL_DEPTH_BUFFER_BIT ¦ GL_ACCUM_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glAccum(GL_ACCUM,0.5); //累积颜色缓存,防止颜色缓存溢出
glLoadIdentity(); // Reset The View

[/Quote]
改过一次忘了改回来了
原来没有注意到
问题已经解决了
谢谢了
vrace 2008-04-03
  • 打赏
  • 举报
回复
每画一帧你都生成了一次材质,你觉得呢。。。


int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
int x, y;
float float_x, L;
L=80.0;

glClear(GL_COLOR_BUFFER_BIT ¦ GL_DEPTH_BUFFER_BIT ¦ GL_ACCUM_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glAccum(GL_ACCUM,0.5); //累积颜色缓存,防止颜色缓存溢出
glLoadIdentity(); // Reset The View

glTranslatef(-98.0f,-50.0f,-5.0f);

glRotatef(-80.0f,1.0f,0.0f,0.0f);


LoadGLTextures(); // <-- 注意这个

glBindTexture(GL_TEXTURE_2D, texture[0]);

Fxingtianxia 2008-04-03
  • 打赏
  • 举报
回复
下载此资源需要:2分

您的积分是:-2分 规则

需要点分下载点资料 渴求中......
dontmakefunofme 2008-04-02
  • 打赏
  • 举报
回复
各位大虾帮帮忙啊

有没有更详细的

谢谢了
dontmakefunofme 2008-04-01
  • 打赏
  • 举报
回复
刚开始的效果





后来





别人做的效果


不知道在渲染方面还能改才能达到那种效果

希望各位大侠指点谜经

愿意把所有份送上
rediscovery 2008-04-01
  • 打赏
  • 举报
回复
内存泄漏?呵呵代码太多了,没心思看。
dontmakefunofme 2008-04-01
  • 打赏
  • 举报
回复
int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
int x, y;
float float_x, L;
L=80.0;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ACCUM_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glAccum(GL_ACCUM,0.5); //累积颜色缓存,防止颜色缓存溢出
glLoadIdentity(); // Reset The View

glTranslatef(-98.0f,-50.0f,-5.0f);

glRotatef(-80.0f,1.0f,0.0f,0.0f);


LoadGLTextures();

glBindTexture(GL_TEXTURE_2D, texture[0]);


if(ii>40||ii<0)
ii=0;
///////////////////////////////////////////////////纹理扰动影射点计算///////////////////////////////////////////////////////
for(x=0;x<99;x++)
{
for(y=0;y<99;y++)
{
potex[x][y][0]=0.1+(2.0*float(x)+(points[ii][x][y][2]-points[ii][x+1][y][2])/2.0*(L-points[ii][x][y][2]))/250.0;
potex[x][y][1]=0.1+(2.0*float(y)+(points[ii][x][y][2]-points[ii][x][y+1][2])/2.0*(L-points[ii][x][y][2]))/250.0;
normal[x][y][0]=(points[ii][x][y][2]-points[ii][x+1][y][2])/2.0;
normal[x][y][1]=(points[ii][x][y][2]-points[ii][x][y+1][2])/2.0;
normal[x][y][2]=sqrt(1-normal[x][y][0]*normal[x][y][0]-normal[x][y][1]*normal[x][y][1]);
}
}
y=99;
for(x=0;x<99;x++)
{
potex[x][y][0]=0.1+(2.0*float(x)+(points[ii][x][y][2]-points[ii][x+1][y][2])/2.0*(L-points[ii][x][y][2]))/250.0;
potex[x][y][1]=0.1+(2.0*float(y)+(points[ii][x][y-1][2]-points[ii][x][y][2])/2.0*(L-points[ii][x][y][2]))/250.0;
normal[x][y][0]=(points[ii][x][y][2]-points[ii][x+1][y][2])/2.0;
normal[x][y][1]=(points[ii][x][y-1][2]-points[ii][x][y][2])/2.0;
normal[x][y][2]=sqrt(1-normal[x][y][0]*normal[x][y][0]-normal[x][y][1]*normal[x][y][1]);
}
x=99;
for(y=0;y<99;y++)
{
potex[x][y][0]=0.1+(2.0*float(x)+(points[ii][x-1][y][2]-points[ii][x][y][2])/2.0*(L-points[ii][x][y][2]))/250.0;
potex[x][y][1]=0.1+(2.0*float(y)+(points[ii][x][y][2]-points[ii][x][y+1][2])/2.0*(L-points[ii][x][y][2]))/250.0;
normal[x][y][0]=(points[ii][x-1][y][2]-points[ii][x][y][2])/2.0;
normal[x][y][1]=(points[ii][x][y][2]-points[ii][x][y+1][2])/2.0;
normal[x][y][2]=sqrt(1-normal[x][y][0]*normal[x][y][0]-normal[x][y][1]*normal[x][y][1]);
}
potex[99][99][0]=0.1+(2.0*99.0+(points[ii][98][99][2]-points[ii][99][99][2])/2.0*(L-points[ii][99][99][2]))/250.0;
potex[99][99][1]=0.1+(2.0*99.0+(points[ii][99][98][2]-points[ii][99][99][2])/2.0*(L-points[ii][99][99][2]))/250.0;
normal[99][99][0]=(points[ii][98][99][2]-points[ii][99][99][2])/2.0;
normal[99][99][1]=(points[ii][99][98][2]-points[ii][99][99][2])/2.0;
normal[99][99][2]=sqrt(1-normal[99][99][0]*normal[99][99][0]-normal[99][99][1]*normal[99][99][1]);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


glBegin(GL_QUADS);

for( x = 0; x < 99; x++ )
{
for( y = 0; y < 99; y++ )
{

glTexCoord2f(potex[x][y][0],potex[x][y][1]);
glNormal3f(normal[x][y][0],normal[x][y][1],normal[x][y][2]);
glVertex3f( points[ii][x][y][0], points[ii][x][y][1], points[ii][x][y][2] );

glTexCoord2f(potex[x][y+1][0],potex[x][y+1][1]);
glNormal3f(normal[x][y+1][0],normal[x][y+1][1],normal[x][y+1][2]);
glVertex3f( points[ii][x][y+1][0], points[ii][x][y+1][1], points[ii][x][y+1][2] );

glTexCoord2f(potex[x+1][y+1][0],potex[x+1][y+1][1] );
glNormal3f(normal[x+1][y+1][0],normal[x+1][y+1][1],normal[x+1][y+1][2]);
glVertex3f( points[ii][x+1][y+1][0], points[ii][x+1][y+1][1], points[ii][x+1][y+1][2] );

glTexCoord2f(potex[x+1][y][0],potex[x+1][y][1]);
glNormal3f(normal[x+1][y][0],normal[x+1][y][1],normal[x+1][y][2]);
glVertex3f( points[ii][x+1][y][0], points[ii][x+1][y][1], points[ii][x+1][y][2] );
}
}

/* glColor4f(1.0,1.0,1.0,1.0);
glTexCoord2f(0.10,0.90);
glVertex3f(200.0,200.0,-10.0);
glTexCoord2f(0.90,0.90);
glVertex3f(0.0,200.0,-10.0);
glTexCoord2f(0.90,0.10);
glVertex3f(0.0,200.0,200.0);
glTexCoord2f(0.10,0.10);
glVertex3f(200.0,200.0,200.0);*/


glEnd();




/* if( wiggle_count == 2 )
{
for( y = 0; y < 45; y++ )
{
hold=points[0][y][2];
for( x = 0; x < 44; x++)
{
points[x][y][2] = points[x+1][y][2];
}
points[44][y][2]=hold;
}
wiggle_count = 0;
}*/

wiggle_count++;
if(wiggle_count%3==0)
ii=ii+1;
if(wiggle_count==999)
wiggle_count=1;
/* xrot+=0.3f;
yrot+=0.2f;
zrot+=0.4f;*/
if(ii==40)
ii=ii-40;
return TRUE; // Keep Going
}





其中的points数组是存放波高的

网格 是100*100的每个面元的面积是2*2m的

总共只有40桢画面循环播放
dontmakefunofme 2008-04-01
  • 打赏
  • 举报
回复
int LoadGLTextures() // Load Bitmaps And Convert To Textures
{
int Status=FALSE; // Status Indicator

AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture

memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL

// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
if (TextureImage[0]=LoadBMP("Data/Tim.bmp"))
{
Status=TRUE; // Set The Status To TRUE

glGenTextures(1, &texture[0]); // Create The Texture

// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}

if (TextureImage[0]) // If Texture Exists
{
if (TextureImage[0]->data) // If Texture Image Exists
{
free(TextureImage[0]->data); // Free The Texture Image Memory
}

free(TextureImage[0]); // Free The Image Structure
}

return Status; // Return The Status
}

GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window
{
if (height==0) // Prevent A Divide By Zero By
{
height=1; // Making Height Equal One
}

glViewport(0,0,width,height); // Reset The Current Viewport

glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix

// Calculate The Aspect Ratio Of The Window
gluPerspective(35.0f,(GLfloat)width/(GLfloat)height,80.106f,261.3f);

glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
}

int InitGL(GLvoid) // All Setup For OpenGL Goes Here
{
if (!LoadGLTextures()) // Jump To Texture Loading Routine ( NEW )
{
return FALSE; // If Texture Didn't Load Return FALSE
}

glEnable(GL_TEXTURE_2D); // Enable Texture Mapping ( NEW )
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.2109375,0.390625,0.72265625,0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup

// glEnable(GL_ATUO_NORMAL);
GLfloat mat_ambient[]={0.410625,0.59375,0.67969,0.5}; //
GLfloat mat_diffuse[]={0.410625,0.59375,0.67969,0.5}; //
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; //
GLfloat white_light[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess[] = {100.0};//
GLfloat light_position[] = {0.0,100.0,100.0, 0.0 };//
GLfloat fogColor[4] = {0.6, 0.6, 0.6, 0.2};//
glLightfv(GL_LIGHT0, GL_POSITION, light_position);//
glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light);//
glLightfv(GL_LIGHT0, GL_SPECULAR, white_light);//
glMaterialfv(GL_BACK, GL_AMBIENT, mat_ambient);//
glMaterialfv(GL_BACK, GL_DIFFUSE, mat_diffuse);//
glMaterialfv(GL_BACK, GL_SPECULAR, mat_specular);//
glMaterialfv(GL_BACK, GL_SHININESS, mat_shininess);//
glEnable(GL_LIGHTING);//
glEnable(GL_LIGHT0);//

glDepthFunc(GL_LESS);//




glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE);//
/* glEnable(GL_FOG);//
{
glFogi (GL_FOG_MODE, GL_LINEAR);
glFogfv (GL_FOG_COLOR, fogColor);
glFogf (GL_FOG_START, 0.0);
glFogf (GL_FOG_END,3.0);
glHint (GL_FOG_HINT, GL_DONT_CARE);
// glClearColor(0.3, 0.3, 0.3, 1.0);
}*/

glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
glPolygonMode( GL_BACK, GL_FILL ); // Back Face Is Solid
glPolygonMode( GL_FRONT, GL_LINE ); // Front Face Is Made Of Lines

/* for(int x=0; x<45; x++)
{
for(int y=0; y<45; y++)
{
points[x][y][0]=float((x/5.0f)-4.5f);
points[x][y][1]=float((y/5.0f)-4.5f);
points[x][y][2]=float(sin((((x/5.0f)*40.0f)/360.0f)*3.141592654*2.0f));
}
}*/
read();
return TRUE; // Initialization Went OK
}

dontmakefunofme 2008-04-01
  • 打赏
  • 举报
回复
void read()
{
int i,j,k;
ifstream fin("d:\\wave200.wa"); //转换后文件路径
for(i=0;i<40;i++)
{
for(j=0;j<100;j++)
{
for(k=0;k<100;k++)
{
fin>>points[i][j][k][0];
fin>>points[i][j][k][1];
fin>>points[i][j][k][2];
}
}
}
fin.close();
}



AUX_RGBImageRec *LoadBMP(char *Filename) // Loads A Bitmap Image
{
FILE *File=NULL; // File Handle

if (!Filename) // Make Sure A Filename Was Given
{
return NULL; // If Not Return NULL
}

File=fopen(Filename,"r"); // Check To See If The File Exists

if (File) // Does The File Exist?
{
fclose(File); // Close The Handle
return auxDIBImageLoad(Filename); // Load The Bitmap And Return A Pointer
}

return NULL; // If Load Failed Return NULL
}

dontmakefunofme 2008-04-01
  • 打赏
  • 举报
回复
[Quote=引用楼主 dontmakefunofme 的帖子:]
回调函数display循环
刚开始的时候很快
后来就卡了
提示虚拟内存太低(我的内存是1g的。cpu奔4 3.0的)
后来波浪就没有颜色了
变成纯白的,并且纹理贴图也没有了
display中也有清除颜色和深度缓存的命令
不知道问题出在哪里
[/Quote]

谢谢楼上的提醒




下面是以部分代码
主要是纹理贴图
和display回调函数的

#include <windows.h> // Header File For Windows
#include <stdio.h> // Header File For Standard Input/Output
#include <fstream.h>
#include <shlobj.h>
#include <math.h> // Header File For The Math Library
#include <gl\gl.h> // Header File For The OpenGL32 Library
#include <gl\glu.h> // Header File For The GLu32 Library
#include <gl\glaux.h> // Header File For The Glaux Library

HDC hDC=NULL; // Private GDI Device Context
HGLRC hRC=NULL; // Permanent Rendering Context
HWND hWnd=NULL; // Holds Our Window Handle
HINSTANCE hInstance; // Holds The Instance Of The Application

bool keys[256]; // Array Used For The Keyboard Routine
bool active=TRUE; // Window Active Flag Set To TRUE By Default
bool fullscreen=TRUE; // Fullscreen Flag Set To Fullscreen Mode By Default

float points[40][100][100][3],potex[100][100][2],normal[100][100][3]; // The Array For The Points On The Grid Of Our "Wave"
int wiggle_count = 0,ii=0,jj=0; // Counter Used To Control How Fast Flag Waves

GLfloat xrot; // X Rotation ( NEW )
GLfloat yrot; // Y Rotation ( NEW )
GLfloat zrot; // Z Rotation ( NEW )
GLfloat hold; // Temporarily Holds A Floating Point Value

GLuint texture[1]; // Storage For One Texture ( NEW )

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc





dontmakefunofme 2008-04-01
  • 打赏
  • 举报
回复

DRACULAX05 2008-03-31
  • 打赏
  • 举报
回复
不贴代码谁知道哦

19,468

社区成员

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

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