Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Dannyli

Member Since 02 May 2013
Offline Last Active Aug 26 2013 01:42 PM

Topics I've Started

How to move object in Directx?

26 August 2013 - 12:43 PM

in opengl, if I want move an object ,a box, I can type:

glPushMatrix();
glTranslatef(x,y,z);
drawBox();
glPopMatrix();

Can someone tell me how to do the same effect in Directx?


texture problem

17 August 2013 - 02:19 PM

I use the following code to generate two textures:

ter=Loadtexture("terrain.bmp",ter);
	cross=Loadtexture("cross.bmp",cross);

but all the objects in the scence are bind with texture 

cross=Loadtexture("cross.bmp",cross);

can someone tell me why?


something about the Billboards

28 July 2013 - 09:18 AM

I am a novice in the tree design. I have a question about the code :

void baiscobj::ShowTree(float x,float z,float h,float s,int cactus)
{ glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glEnable(GL_ALPHA_TEST);
  glAlphaFunc(GL_GREATER, 0);
  float mat[16];
  glGetFloatv(GL_MODELVIEW_MATRIX, mat);
  vector3_t X(mat[0], mat[4], mat[8]);
  vector3_t Z(mat[1], mat[5], mat[9]); 
  glBindTexture(GL_TEXTURE_2D, g_cactus[cactus]);
  vector3_t pos(x,0.0,-z);
  pos.y = GetHeight(x, -z) + h + s;
  glBegin(GL_QUADS);
glTexCoord2f(0.0,0.0);glVertex3fv((pos+(X+Z)*-h).v);//left down
glTexCoord2f(1.0,0.0);glVertex3fv((pos+(X-Z)* h).v);//up down
glTexCoord2f(1.0,1.0);glVertex3fv((pos+(X+Z)* h).v);//up right
glTexCoord2f(0.0,1.0);glVertex3fv((pos+(Z-X)* h).v);//left up
  glEnd();
  glDisable(GL_ALPHA);
  glDisable(GL_BLEND);
}

why the line glVertex3fv((pos+(X+Z)*-h).v); can rotate the point? pos+(X+Z)*-h is a translation , isn't it?

 


problem with load obj file

18 June 2013 - 03:46 PM

I try to load the obj file to the opengl but the system crash, I tested My code in console system:

#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <ostream>
#include <algorithm>
#include <Windows.h>
using namespace std;

class vertex
{public:
float f1;
float f2;
float f3;
vertex(float F1,float F2, float F3):f1(F1),f2(F2),f3(F3){};
};//the vertex

class face{
public:
	int a;
	int b;
	int c;
	int d;
	bool four;
	face(int x,int y,int z):a(x),b(y),c(z){four =false;};
	face(int x,int y,int z,int k):a(x),b(y),c(z),d(k){four =true;};
};

vector<vertex>v;
vector<face>f;

void loadvertex(char*filename){

	ifstream infile(filename);
	ofstream outfile("out.txt");
	float f1,f2,f3;
	char buffer;
	if(!infile.is_open())
	{return;
	}
	while(infile>>buffer>>f1>>f2>>f3){
	if(buffer=='v')
	{outfile<<f1<<" "<<f2<<" "<<f3<<endl;
	cout<<f1<<" "<<f2<<" "<<f3<<endl;
	v.push_back(vertex(f1,f2,f3));}
	
	}

	infile.close();
	outfile.close();

}


void loadface(char*filename){
	ifstream infile(filename);
	ofstream outfile("out.txt");
	int f1,f2,f3;
	char buffer;
	if(!infile.is_open())
	{return;
	}
	while(infile>>buffer>>f1>>f2>>f3){
	if(buffer=='f'){

	outfile<<f1<<" "<<f2<<" "<<f3<<endl;
	cout<<f1<<" "<<f2<<" "<<f3<<endl;
	f.push_back( face(f1,f2,f3));
	}
	}

	infile.close();
	outfile.close();
}
void Loadobj(char*filename)
{
string line;
ifstream objfile(filename);
if(objfile.is_open())
{

while(!objfile.eof())
{ getline(objfile,line);
  if(line.c_str()[0]=='v')
 {  float tmpx,tmpy,tmpz;
   sscanf(line.c_str(),"v %f %f %f",&tmpx,&tmpy,&tmpz);
   v.push_back(vertex(tmpx,tmpy,tmpz));
}
  if(line.c_str()[0]=='f')
  {  int a,b,c,d;
   sscanf(line.c_str(),"f %d//%d %d//%d %d//%d",&a,&b,&c,&b,&d,&b);
   f.push_back(face(a,c,d));
}
}
}

}
int main(){
	Loadobj("cube.txt");
	for(int i=0;i<f.size();i++)
	{ 
		float F1=v[f[i].a-1].f1;
		float F2=v[f[i].a-1].f2;
		float F3=v[f[i].a-1].f3;
		cout<<F1<<"--"<<F2<<"--"<<F3<<endl;
	
	}
	system("pause");
	return 0;
}

the obj file:

 

# Blender3D v249 OBJ File: 
# www.blender3d.org
v 1.000000 1.000000 -1.000000
v 1.000000 -1.000000 -1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 1.000000 -1.000000
v 1.000000 0.999999 1.000000
v 0.999999 -1.000001 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 1.000000 1.000000
vn 0.000000 1.000000 0.000000
vn -1.000000 0.000000 -0.000000
vn -0.000000 -1.000000 -0.000000
vn 1.000000 0.000000 -0.000000
vn 1.000000 -0.000001 0.000000
vn 0.000000 0.000000 1.000000
vn 0.000000 0.000000 -1.000000
usemtl Material
s off
f 5//1 1//1 4//1
f 5//1 4//1 8//1
f 3//2 7//2 8//2
f 3//2 8//2 4//2
f 2//3 6//3 3//3
f 6//3 7//3 3//3
f 1//4 5//4 2//4
f 5//5 6//5 2//5
f 5//6 8//6 6//6
// the error shows that: ...
if (longone)
//                                    *(long UNALIGNED *)pointer = (unsigned long)number;
  //                             else...

problem with the texture loading in opengl

26 May 2013 - 07:06 PM

void texload(int i,char *filename)
{
    BITMAPINFOHEADER bitmapInfoHeader;                                 
	unsigned char*   bitmapData;                                       

   bitmapData = LoadBitmapFile(filename, &bitmapInfoHeader);
   glBindTexture(GL_TEXTURE_2D, texture[i]);  
	
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);//filter

	glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB,bitmapInfoHeader.biWidth,bitmapInfoHeader.biHeight,0,GL_RGB,GL_UNSIGNED_BYTE,bitmapData);	
}  

 

  The compiler throw out exception on the line

 glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB,bitmapInfoHeader.biWidth,bitmapInfoHeader.biHeight,0,GL_RGB,GL_UNSIGNED_BYTE,bitmapData); 

 

My BMP file is 252x255, is that too big for my function?


PARTNERS