Jump to content

  • Log In with Google      Sign In   
  • Create Account

xXDreamXx

Member Since 27 Aug 2011
Offline Last Active Jul 09 2014 08:34 PM

Topics I've Started

OpenGL Rendering over SDL

24 October 2012 - 07:45 PM

Hey guys. My problem may be pretty simple. I am writing some code for a world. I have it where opengl renders and sdl does everything else. The problem is that SDL wants to render before opengl, and if It doesn't create a screen I can't control my audio sound effect events. Does anyone know how to make SDL no render and give me only audio and controls with opengl doing the rendering thanks.

I will attach the current code of the audio for sdl. The issue is that if I don't have
SDL_Surface *screen;
screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);

uncommented out; I am not able to use my events. Worse it will not let opengl render over SDL.

I will not let me upload the file so here is the code.


/*This program is a test program for using SDL Mixer to create sound in programs
Music and file loading on program works great. I just need to figure out how to control audio effect events without
SDL needing to create a screen.
I also need to put this into a function
Note: The only issue with the program is that I can't controly my audio effect events unless I let SDL create a screen*/

#include <SDL/SDL.h>
#include "SDL_mixer.h" //This include library directory may change on different machines


//SDL sound function
void SDL_Sound()
{
SDL_Init(SDL_INIT_AUDIO);
SDL_Surface *screen; //test
screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE); //test
Mix_Chunk* effect1; //new varible to create effects from SDL lib
Mix_Music* music; //used to create the music

//Open Audio
Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT,2, 4096);//require 4 parameters ( references (default 22050 or 41000), format(how to open,number of channels , chunk size)

//Loading Music
music = Mix_LoadMUS("Train.wav"); //assigns music to load Mix_LoadMUS(filenam. filetype)

//Assiging music to load
effect1=Mix_LoadWAV("TrainHorn.wav");

//Playing the music
Mix_PlayMusic(music,-1);//Telling program to play the music (play music file, how long to play 0 = play once, -1 = repeat, 1 = will repeat once)


//now to control the effect when key is pressed
bool running=true; //boolean expression to make true
Uint32 start;
//SDL_Event event;
while(running)
{

start=SDL_GetTicks();
SDL_Event event;
while(SDL_PollEvent(&event))
{

switch(event.type)
{
case SDL_QUIT:
running=false;
break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{

case SDLK_1: //number key 1 can be pressed
Mix_PlayChannel(-1, effect1, 0);// there are a total of 8 channels (channel, effect to play, how to repeat)
break;
case SDLK_2: //number key 1 can be pressed
running = false;
break;
}
}
}

};
Mix_FreeChunk(effect1);
Mix_FreeMusic(music);
}



int main(int argc,char** argv)
{


SDL_Sound();


//Closing Audio
Mix_CloseAudio();
SDL_Quit();
return 0;
}

How do I make the gltranslate function not effect other objects below it

22 October 2011 - 07:40 AM

Hey guys, I am wondering is there any possible way for me to reset the translate function so that it does affect the geometry that I am creating below it. I am using multiple display list so when I use gltranslate it moves everything by that translation, when I actually only want one thing to be translate then end the translate. Is there any way to do it? For example I have: (This is not the actually code, but similar layout. I know the syntax isn't correct in the example.)

glTranslatef(x, y, z);

displaylist(item1);

// I would like to end translate here.

//I would like to end the translate before I create the other object

glTranslatef(u,v,w); //New translation that I don't want effected by the previous translate
displaylist(item2);

//I would like to end this new translate and not effect the other display list declared below it


Is this possible? Or do I have to subtract the pervious translation from the new translation to make it go back to the original position

Putting Models on Terrain Surface

03 October 2011 - 09:53 AM

Hi guys. I am new to OpenGL. I am trying to figure out a way to make my models be on my terrain. I am kind of confused on how to approach the situation. My terrain is actually an .obj file, so it is easy to apply textures to it. I am wondering should I store every point in the terrain, and try to find the relevant coordinates that are in the same area as my object, then translate it? Or is there an easier way to calculate the top of my terrain, and make some type of collision detection so that the no geometry can go below the terrain?

Here is a picture of the terrain's geometry and its UV map:
Attached File  Terrain Test Model.jpg   362.99KB   49 downloads


Here is the Terrain Textured:
Attached File  Solid Pattern Terrain.jpg   328.22KB   49 downloads

Here is the Terrain Rendered in OpenGL:
Attached File  TerrainTestSuccessful.jpg   48.57KB   42 downloads

Here is a house on the terrain, but it is not automatically calculated by the program:

Attached File  Translate House on Terrain.jpg   111.1KB   34 downloads
Attached File  Translate House on Terrain2.jpg   74.31KB   32 downloads

My goal is develop something to automatically place the models directly on the surface of the terrain. How would I go about doing that anyone?

How do you read in Digital Elevation Model (dem) data from usgs.gov

27 September 2011 - 07:12 AM

Hi guys. I am trying to replicate some terrain and display it with OpenGL I am getting the data form http://seamless.usgs.gov/ then I go to Tools to Access Data then select the seamless viewer. The next part is a little strange to me. I know how to select my area, and I want the elevation data. Alot of sites says that the data suppose to be outputed as ascii format, but I cann't read the files with word pad or notepad. Better yet its so many files I don't know which to even get the data from. Since I am new to this. I am trying to get the vector data for the elevation and have it in ascii format so that I can know what I am looking at to read the data in. Does anyone know how to do this? The national map seamless server address is http://seamless.usgs.gov/website/seamless/viewer.htm. The goal is to get the elevation data into a vector format so that I can read it into opengl to generate my terrain. Let me know if you guys know of some better approaches as well but I need to work with the digital elevation model (dem) data. Thanks for the help.

Making multiple texture objects with OpenGL and SDL

21 September 2011 - 05:27 PM

Hi guys. I am having a little trouble using opengl to read in multiple textures. The issue is that I am trying to display multiple objects and assign one UV map to that texture. I can read in on model and texture find, but for 2 models it seems to only load up the last texture id for both models. So basically I want to display a house and a cube. I have both uv maps but only the final texture is loading. Can anyone let me know how to load up multiple textures without overwriting others, something like a texture array or somthing?

Here is an example of what I am getting:

Attached File  Texture multiple issue.jpg   39.7KB   63 downloads


If you notice the texture for the cube is correct, while the texture for the house was over written, since the cube is the last texture to be read in.
Here is the code below:
The code shows me loading in the texture, and the makeGeometry function is just use to create display list and state which file and texture to load:

[/code start]

//*********CURRENTLY: WORKING ON DISPLAYING MULTIPLE TEXTURES

//Texture counter variable for texture id, Tid

int Tid=1;

unsignedint loadTexture(constchar* filenameTex)

{

//Here just trying to load in two different textures

SDL_Surface* img =SDL_LoadBMP(filenameTex); //figure out why color isn't coming in

unsignedint id[3]; //assigning an id for glGenTextures

glGenTextures(2, &id[Tid-1]); //idea assigned (how many textures to generate, &texture id)

glBindTexture(GL_TEXTURE_2D,id[Tid-1]); //binding texture to the id

Tid++;

glTexImage2D(GL_TEXTURE_2D,

0,

GL_RGB,

img->w,
//width of image

img->h, //height of image

0,

GL_BGR,
//format Note: sometimes the color scheme can be reversed to BGR or not reversed it is RGB

GL_UNSIGNED_BYTE, //what format is the image stored

img->pixels); //pixel array, pixels



//Setting Parameters

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

//Warping Parameters (how texture will be applied to the object)

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //Many different parameters can be set her to manipulate the textures

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

//Filtering Parameters

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //2d texture with a minimum filter, and linear interpolation (averaging pixlels)

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

SDL_FreeSurface(img);
//deletes the texture image out of the texture memory
return id[Tid-1];

}

//***********************Display List Section******************************************************

void makeGeometry() //Function that uses display list to build the geometry

{

//Test area



OpenFile(
"house.obj", "houseUV_Cube.bmp"); //This is just passed to a function OpenFile(obj file, file texture.bmp)

//holder.FName is the obj file, holder.FTexture is the texture read in for the file

tex = loadTexture(holder.FTexture); //texture

readFileCount(holder.FName);

readFile(holder.FName);
//geometry file



//End Test area

listIndex = glGenLists (1); //creates display list name and size of 1 for the model, this may have to be adjusted for importing multiple geometries

glNewList(listIndex, GL_COMPILE);

//Now start here to build the geometry of the model

//This section will go into the display function

glBegin(GL_TRIANGLES);



//Section will decide if normals are read in or not by the conditional if statement

if(NormExist == 0)

{

for(int i=0; i<countObj.F*3; i++)

{

glTexCoord2f(texPoint[i].u,1-texPoint[i].v);
//Here I had to put 1-y-coordinate since openGL starts reading textures from (0,0), bottom left

glVertex3f(makePoint[i].x, makePoint[i].y,makePoint[i].z);

}

}

else

{

for(int i=0; i<countObj.F*3; i++)

{

glNormal3f(VNormPoint[i].x,VNormPoint[i].y,VNormPoint[i].z);

glTexCoord2f(texPoint[i].u,1-texPoint[i].v);
//Here I had to put 1-y-coordinate since openGL starts reading textures from (0,0), bottom left

glVertex3f(makePoint[i].x, makePoint[i].y,makePoint[i].z);

}

}

glEnd();

glEndList();
//glCallList(listIndex); is used to call the read in data

//Test area****** To load in second model



OpenFile(
"cube.obj", "cube_Cube.bmp");

tex = loadTexture(holder.FTexture);
//load up texure file original code

readFileCount(holder.FName);

readFile(holder.FName);

listIndex2 = glGenLists (2);
//creates display list name and size of 1 for the model, this may have to be adjusted for importing multiple geometries

glNewList(listIndex2, GL_COMPILE);

//Now start here to build the geometry of the model

//This section will go into the display function

glBegin(GL_TRIANGLES);



//Section will decide if normals are read in or not by the conditional if statement

if(NormExist == 0)

{

for(int i=0; i<countObj.F*3; i++)

{



glTexCoord2f(texPoint[i].u,1-texPoint[i].v);
//Here I had to put 1-y-coordinate since openGL starts reading textures from (0,0), bottom left

glVertex3f(makePoint[i].x, makePoint[i].y,makePoint[i].z);

}

}

else

{

for(int i=0; i<countObj.F*3; i++)

{

glNormal3f(VNormPoint[i].x,VNormPoint[i].y,VNormPoint[i].z);

glTexCoord2f(texPoint[i].u,1-texPoint[i].v);
//Here I had to put 1-y-coordinate since openGL starts reading textures from (0,0), bottom left

glVertex3f(makePoint[i].x, makePoint[i].y,makePoint[i].z);



}

}

glEnd();

glEndList();
//glCallList(listIndex2); is used to call the read in data

//For some reason this seems to be reading in one texture, displaying the final texture and overwriting the previous

//End Test area***

}



[/code end]]

The code works find. I just don't understand how to display multiple textures and the book that I have doesn't state it. Thanks guys.

PARTNERS