android – Kotlin Listar valores de Retrofit en un RecyclerView dentro de un Fragment

estoy realizando una app para android con Kotlin, MVVM y esta consume una API REST mi petición la estoy realizando correctamente ya que me da un status 200 pero creo que al procesar los datos del request en android y mostrarlos dentro del recyclerView no lo estoy realizando correctamente pues muestra valores null si alguien puede decirme en que me equivoque o me falta ya llevo 2 días con esto dejo mi código para demostrarlo mejor

Postman JSON
{
“listaPatologias”: (
{
“patologiaId”: 1,
“categoriaId”: 1,
“nombre”: “Alérgicos”,
“padecePaciente”: false
},
{
“patologiaId”: 2,
“categoriaId”: 1,
“nombre”: “Hospitalizaciones”,
“padecePaciente”: false
},
{
“patologiaId”: 3,
“categoriaId”: 1,
“nombre”: “Quirúrgicos”,
“padecePaciente”: false
},
),
“mensaje”: “Patologias obtenidas con éxito”,
“estatus”: true
}

        Retrofit
     
     @GET("api/ServiciosPaciente/GetPatologias")
         suspend fun getEnfermedades(
             @Header("Authorization") token: String,
             @Query("PacienteId") paciente: String
         ): Response<ListaPatologias>
     
     

 

    Models
     
     data class ListEnfermedad(
         val estatus: Boolean,
         val listaPatologias: List<ListaPatologias>,
         val mensaje: String )
     
     data class ListaPatologias(
         val categoriaId: Int,
         val nombre: String,
         val padecePaciente: Boolean,
         val patologiaId: Int )

     Repo
     
      suspend fun getDisease(token: String, paciente: String):
     Response<ListaPatologias>{
             return RetrofitInstance.api.getEnfermedades(token, paciente)
         }
     

 

    ViewModel
    
           fun getEnfermedad(token: String, paciente: String){
             viewModelScope.launch {
                 val response = repository.getDisease(token, paciente)
                 Log.d("userEnfermedad",  response.toString())
                 myListDiseaseResponse.value = response
             }
         }

 

        RetrofitInstance
    
    object RetrofitInstance {
        private val retrofit by lazy{
            Retrofit.Builder()
                 .baseUrl(AppConstants.BASE_URL)
                 .addConverterFactory(GsonConverterFactory.create())
                 .build()
        }
    
        val api: ApiService by lazy {
            retrofit.create(ApiService::class.java)
        }
    }

RecyclerViewAdapter y ViewHolder

    class EnfermedadAdapter : RecyclerView.Adapter<EnfermedadAdapter.myViewHolder>(){

    private var myList = emptyList<ListaPatologias>()

    inner class myViewHolder(itemView: View): RecyclerView.ViewHolder(itemView)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EnfermedadAdapter.myViewHolder {
        return myViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.sciknees_list_item, parent, false))
    }

    override fun getItemCount(): Int {
        return myList.size
    }

    override fun onBindViewHolder(holder: myViewHolder, position: Int) {
        holder.itemView.name_sickneess.text = myList(position).nombre
    }

    fun setData(newList: ListaPatologias){
        myList = listOf(newList)
        notifyDataSetChanged()
    }
}
   

java – ¿Como solucionar el error appCompatActivity al querer agregar la funcion de regresar atras desde toolbar en un fragment?

en esta ocasión vengo con un error que me salio ya que quiero agregar la función de retroceder hacia atrás desde fragment, ya que tengo los títulos en toolbar solo me falta el retroceso y me lleve al menú principal.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    ((AppCompatActivity)getActivity()).getSupportActionBar().setTitle("Servicios");
    appCompatActivity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);


    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.fragment_volcan_popocatepetl, container, false);


}

** Captura de error**
introducir la descripción de la imagen aquí

algorithm – “Smoothing” colors in mutliple-color gradient in fragment shader

TL;DR How to better avoid some of the colors in the gradient looking like brighter/darker lines and make them blend in with neighboring colors. Not too concerned with performance/color accuracy but don’t like how my algorithm muddies up colors at higher blend settings.

Longer explanation

I initially wrote a straight-forward gradient algorithm which linearly transitions between colors. This works fine however there was one aspect that I didn’t like about the result: the points in the gradient where there is just the pure color stood out too much.

For example, on the image below the white color in the middle looks like a bright line – I would like to somehow soften this – going for aesthetics over color accuracy.

enter image description here

Idea behind algorithm attempt to smooth out “peaks”

The simple linear case, assuming 2 colors, can be represented as a graph with the proportion of color 1 represented by a straight line going from (0, 1) to (1, 0) (y = 1 – x) and another one (color 2) going from (0, 0) to (1, 1) (y = x). My idea is to limit the lowest and highest points, so that for example the lines become (0, 0.8) to (1, 0.1) and (0, 0.1) to (1, 0.8) and hence there is never just the single color shown. The top boundary is limited at 1 – (2 * bottom) because when there are more than 2 colors, the middle colors will have 2 neighbors.

The algorithm and resulting gradients are below. Even with high proportions of neighboring colors mixed in, I still think the “lines” (light red near the top, dark purple in the middle and light green near the bottom on the right sample) are too visible (this had an input of 10 colors, which my algorithm unfortunately also muddies up):

enter image description hereenter image description here

Is there a better approach to blur the boundaries? I thought about using a quadratic/curved function, but it seems like that will just lead to an even wider plateau, or a narrow but sharp peak depending on which way it’s facing.

#ifdef GL_ES
precision mediump float;
#endif

uniform vec2 iResolution;

//input - array of colors
uniform vec3 iColors(10);
//input - actual number of colors in the array
uniform int iNumColors; 

void main(void) {
    // x, y co-ordinates, 0 to 1
    vec2 uv = gl_FragCoord.xy / iResolution.xy;
    // flip y axis so first color is on top
    uv.y = 1.0 - uv.y;
    float transparency = 1.0;

    //if only one color, return uniform color
    if (iNumColors == 1) {
        gl_FragColor = vec4(iColors(0), transparency);
        return;
    }

    // init to black - rgb channels 0 to 1
    vec3 color = vec3(0.);
    
    float colorWidth = 1.0 / float(iNumColors - 1);

    for (int i = 0; i < iNumColors; i++) {
        // location of "peak" of current color
        float midPoint = float(i) * colorWidth;
        float colorValue;
        
        float overlap = 0.25;
        float top = 1. - (overlap * 2.);
        float bottom = overlap;
        float height = top - bottom;
        
        float gradient = height / colorWidth;
        float yOffset;
        if (uv.y >= midPoint) {
            gradient *= -1.0;
            yOffset = top + (height * float(i));
        } else {
            yOffset = bottom - (height * float(i - 1));
        }
        colorValue = yOffset + (gradient * uv.y);
        color += iColors(i) * max(0., colorValue);
    }
    gl_FragColor = vec4(color, transparency);
}

java – opengl (lwjgl) – only white triangle gets rendered, vertex and fragment shader not responsive

Currently my program can only render my vertices as white and changes in my vertex and fragment shader don’t change what gets rendered for some reason i.e: (gl_Position = vec4(position+0.5,1); doesn’t shift my triangle).

I’m not getting GL_FALSE from the glGetShaderi and glGetProgrami functions and I know my fragment shader and vertex shader are being read as glGetShaderi(shader,GL_COMPILE_STATUS) == GL_FALSE when I forget my semi-colon.

Anyone know how to solve this?

Vertex Shader:

#version 330

layout (location = 0) in vec3 position;

void main(){
    gl_Position = vec4(position+0.5,1);
}

Fragment Shader:

#version 330

out vec4 fragColor;

void main(){
    fragColor = vec4(1,1,0,1);
}

Main.java:

public class Main {
    static long window;
    private static int WIN_WIDTH = 500;
    private static int WIN_HEIGHT = 500;
    
    public static void main(String() args) {
        // glfwInit
        if (!glfwInit()) {
            throw new IllegalStateException("Error for glfwInit");
        }
        
        // Hint
        glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR,3);
        glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR,2);

        glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
        glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT,GLFW_TRUE);
        
        glfwWindowHint(GLFW_VISIBLE,GLFW_FALSE);
        
        
        // Window
        // window create
        window = glfwCreateWindow(WIN_WIDTH, WIN_HEIGHT, "warmulfollowalong", 0, 0);
        // window check
        if  (window == 0) {
            throw new IllegalStateException("Error creating window");
        }
        
        // CONTEXT
        glfwMakeContextCurrent(window);
        GL.createCapabilities();
        
        // window position
        
        GLFWVidMode videoMode = glfwGetVideoMode(glfwGetPrimaryMonitor());
        glfwSetWindowPos(window, videoMode.width()/2-WIN_WIDTH/2, videoMode.height()/2-WIN_HEIGHT/2);
        
        // window display
        glfwShowWindow(window);
        
        
        
        // CREATE MESH
        Mesh testMesh = new Mesh();
        testMesh.create(new float() {
                -1, -1, 0,
                0,1,0,
                1,-1,-1,
        });
        
        
        //
        Shader shader = new Shader();
        shader.create("shader");
        
        
        // LOOP
        while(!glfwWindowShouldClose(window)) {
            glfwPollEvents();
            
            // clear
            glClearColor(1, 0, 0, 1);
            glClear(GL_COLOR_BUFFER_BIT);
            
            // shader
            shader.useShader();
            
            // DRAW
            testMesh.draw(); 
            
            glfwSwapBuffers(window);
        }

        // destroy
        testMesh.destroy();
        shader.destroy();
        
        // close
        glfwTerminate();
    }
}

Mesh.java:

public class Mesh {
    private int vao;
    private int vbo;
    
    private int vertexCount;
    
    public void Mesh() {
        
    }
    
    public boolean create(float() vertices) {
        // Create VAO and bind it
        vao = glGenVertexArrays();
        glBindVertexArray(vao);

        // Create empty buffer and bind it and bufferData
        vbo = glGenBuffers();
        glBindBuffer(GL_ARRAY_BUFFER, vbo);
        glBufferData(GL_ARRAY_BUFFER,vertices,GL_STATIC_DRAW);
        glVertexAttribPointer(0, 3, GL_FLOAT, false, 0,0);
        
        // Unbind VAO
        glBindVertexArray(0);
        
        // Set vertexCount
        vertexCount = vertices.length / 3;
        
        return true;
    }
    
    public void destroy() {
        // delete vao & vbo
        glDeleteVertexArrays(vao);
        glDeleteBuffers(vbo);
    }
    
    public void draw() {    // Seems very inefficient
        // bind VAO
        glBindVertexArray(vao);
        // enable VBO (essentially) / enable vertex Attribute Array
        glEnableVertexAttribArray(0);   // !@$!@#!@# when to use???
        
        // DRAW
        glDrawArrays(GL_TRIANGLES, 0, vertexCount);

        // disable VBO (essentially) / enable vertex Attribute Array
        glDisableVertexAttribArray(0);
        // unbind VAO
        glBindVertexArray(0);
    }
}

Shader.java:

public class Shader {
    // stores int handle
    private int vertexShader, fragmentShader, program;
    
    public Shader(){
                
    }
    
    public boolean create(String shader) {
        // Create vertex shader
        int vertexShader = glCreateShader(GL_VERTEX_SHADER);
        glShaderSource(vertexShader, readSource(shader+".vs"));
        glCompileShader(vertexShader);
        
        if(glGetShaderi(vertexShader, GL_COMPILE_STATUS) == GL_FALSE) {
            throw new Error("ERROR: compiling vertex shader. Info: "+glGetShaderInfoLog(vertexShader));
        }
        
        // Create fragment shader
        int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
        glShaderSource(fragmentShader,readSource(shader+".fs"));
        glCompileShader(fragmentShader);
        
        if(glGetShaderi(fragmentShader,GL_COMPILE_STATUS) == GL_FALSE) {
            throw new Error("ERROR: compiling fragment shader. Info: "+glGetShaderInfoLog(fragmentShader));
        }
        
        // Program
        int program = glCreateProgram();
        glAttachShader(program, vertexShader);  // !@#!@#!@#
        glAttachShader(program, fragmentShader);
        
        // Program check
        glLinkProgram(program);
        if (glGetProgrami(program, GL_LINK_STATUS) == GL_FALSE) {
            throw new Error("ERROR: linking program. Info: "+glGetProgramInfoLog(program));
        }
        glValidateProgram(program);
        if (glGetProgrami(program,GL_VALIDATE_STATUS) == GL_FALSE) {
            throw new Error("ERROR: validating program. Info: "+glGetProgramInfoLog(program));
        }
        
        
        return true;    // !@#!@# Shouldn't you be passing down the program? Isn't this like an anti pattern?
        
    }
    
    public void destroy() {
        // detach
        glDetachShader(program, vertexShader);
        glDetachShader(program, fragmentShader);
        
        // delete shaders
        glDeleteShader(vertexShader);
        glDeleteShader(fragmentShader);
    
        // delete program
        glDeleteProgram(program);
    }
    
    public void useShader() {
        glUseProgram(program);
    }
    
    public String readSource(String file) {
        BufferedReader reader = null;
        StringBuilder sourceBuilder = new StringBuilder();
        
        try {
            reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/shaders/"+file)));

            String line;
            
            while((line = reader.readLine()) != null) {
                sourceBuilder.append(line+"n");    //<= remember to add new line
            }
        }catch (IOException e) {
            // TODO: handle exception
            e.printStackTrace();
        }finally {
            try {
                //MY
                if(reader != null){
                    reader.close();
                }
            }catch (IOException e) {
                // TODO: handle exception
                e.printStackTrace();
            }
        }
        
        return sourceBuilder.toString();
    }
    
}

```

java – Why I can’t make a list of fragment class?

java – Why I can’t make a list of fragment class? – Android Enthusiasts Stack Exchange

java – BottomNavigationView not visibile in all Fragment

I have a question the kotlin code below defines a BottomNavigationView is visible only in the activity_main and not in the fragments present in the bottombar navigaiton, the gist is that the bottom bar is visible only on the first page and not in the remaining fragments, what is this due to? what do I have to do to make the menu appear in all ui

MainActivity.kt

class MainActivity : AppCompatActivity() {

    private val bottleFragment = BottleFragment()
    private val homeFragment = HomeFragment()
    private val profileInfoFragment = ProfileInfoFragment()
    private val fragmentHistory = mutableListOf<Fragment>(homeFragment)
    private var activeFragment: Fragment = homeFragment
    var ID_AUTH_FIREBASE = ""
    var ADMIN_KEY = ""
    var email = ""
    val bundle = Bundle()

    private val bottomNavigationListener = BottomNavigationView.OnNavigationItemSelectedListener {
        when (it.itemId) {
            R.id.navigation_home -> {
                setFragment(homeFragment)
                return@OnNavigationItemSelectedListener true
            }
            R.id.navigation_profile -> {
                setFragment(profileInfoFragment)
                return@OnNavigationItemSelectedListener true
            }
            R.id.navigation_bottle -> {
                setFragment(bottleFragment)
                return@OnNavigationItemSelectedListener true
            }
            else -> {
                return@OnNavigationItemSelectedListener false
            }
        }
    }

    @SuppressLint("MissingPermission")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        navigation.setOnNavigationItemSelectedListener(bottomNavigationListener)
        startFragment(homeFragment)
        checkPermissions()
        buttonlogout.setOnClickListener { logout() }
        buttonsave.setOnClickListener { save() }
        window.setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN
        );
        email = intent.getStringExtra("Email")
        ID_AUTH_FIREBASE = intent.getStringExtra("ID_AUTH_FIREBASE")
        ADMIN_KEY = intent.getStringExtra("ADMIN_KEY")
        val sharedPreference = getSharedPreferences("PREFERENCE_NAME", 0)
        var editor = sharedPreference.edit()
        editor.putString("Email", email)
        editor.putString("ID_AUTH_FIREBASE", ID_AUTH_FIREBASE)
        editor.putString("ADMIN_KEY", ADMIN_KEY)
        editor.commit()
        val datiPersona = APISupport.getDatiPersona(ID_AUTH_FIREBASE, email, ADMIN_KEY)
        textNome.setText(datiPersona(0))
        txtCognome.setText(datiPersona(1))
        txtResidenza.setText(datiPersona(2))
        txtTelefono.setText(datiPersona(3))
        txtEmail.setText(email)
        hometext.text = datiPersona(0) + " " + datiPersona(1)
        txtcfdesc.setText(datiPersona(5))
        txtnumeropolizaedit.setText(datiPersona(6))
        try {
            val url: URL = URL(APISupport.geturlLogo(ID_AUTH_FIREBASE, email, ADMIN_KEY))
            val bmp: Bitmap = BitmapFactory.decodeStream(url.openConnection().getInputStream())
            imageLogo.setImageBitmap(bmp)
        } catch (e: Exception) {
            System.out.println("Errore")
        }
        txtDataFineEdit.setText(datiPersona(8))
        txtDataInizioEdit.setText(datiPersona(7))

    }


    override fun onResume() {
        super.onResume()
        checkPermissions()
    }

    override fun onPause() {
        super.onPause()
        checkPermissions()
    }

    fun save() {
        var value = APISupport.savedatipersona(
            ID_AUTH_FIREBASE,
            email,
            ADMIN_KEY,
            txtCognome.text.toString(),
            textNome.text.toString(),
            txtTelefono.text.toString(),
            txtResidenza.text.toString(),
            txtDataInizioEdit.text.toString(),
            txtDataFineEdit.text.toString(),
            txtnumeropolizaedit.text.toString(),
            txtcfdesc.text.toString()
        )
    }

    fun logout() {
        val intent = Intent(this, SplashActivity::class.java)
        startActivity(intent)
    }

    fun startFragment(fragment: Fragment, removeLast: Boolean = false) {

        if (fragment == homeFragment)
            startHomeBackground()
        else
            stopHomeBackground()

        if (removeLast)
            fragmentHistory.removeAt(fragmentHistory.lastIndex)
        if (fragmentHistory.last() != fragment)
            fragmentHistory.add(fragment)


        activeFragment = fragment
    }

    protected fun setFragment(fragment: Fragment?) {
        if (fragment == homeFragment)
            startHomeBackground()
        else
            stopHomeBackground()
        val fragmentManager = supportFragmentManager
        val fragmentTransaction: FragmentTransaction = fragmentManager.beginTransaction()
        if (fragment != null) {
            fragmentTransaction.replace(android.R.id.content, fragment)
        }
        fragmentTransaction.commit()
    }


    fun startHomeBackground() {
        homeBackground.visibility = View.VISIBLE
    }

    fun stopHomeBackground() {
        homeBackground.visibility = View.GONE
    }

    private fun checkPermissions() {
        if (ActivityCompat.checkSelfPermission(
                this,
                Manifest.permission.ACCESS_FINE_LOCATION
            ) != PackageManager.PERMISSION_GRANTED
        ) {
            requestPermissions(
                arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
                RequestCodes.PERMISSION_GPS
            )
            return
        }

        if (ActivityCompat.checkSelfPermission(
                this,
                Manifest.permission.BLUETOOTH
            ) != PackageManager.PERMISSION_GRANTED
        ) {
            requestPermissions(
                arrayOf(Manifest.permission.BLUETOOTH),
                RequestCodes.PERMISSION_BLUETOOTH
            )
            return
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            if (ActivityCompat.checkSelfPermission(
                    this,
                    Manifest.permission.FOREGROUND_SERVICE
                ) != PackageManager.PERMISSION_GRANTED
            ) {
                requestPermissions(
                    arrayOf(Manifest.permission.FOREGROUND_SERVICE),
                    RequestCodes.PERMISSION_FOREGROUND_SERVICE
                )
                return
            }
        }

    }

    private fun Fragment.isMainFragment(): Boolean {
        when (this) {
            homeFragment, bottleFragment, profileInfoFragment -> {
                return true
            }
        }
        return false
    }


    override fun onBackPressed() {

        if (fragmentHistory.last().isMainFragment()) {
            finish()
            return
        }

        val lastIndex = fragmentHistory.lastIndex
        try {
            startFragment(fragmentHistory(lastIndex - 1), true)
        } catch (e: IndexOutOfBoundsException) {
            e.printStackTrace()
            finish()
        }
    }


}

activity_main.xml

....
<!-- Bottom Navigation View -->
    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="0dp"
        android:layout_height="85dp"
        android:background="#FFFAFA"
        android:backgroundTint="@android:color/transparent"
        app:itemBackground="@android:color/transparent"
        app:itemIconSize="28dp"
        app:itemIconTint="@color/bottom_navigation_color"
        app:labelVisibilityMode="unlabeled"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/bottom_navigation" />
..

bottom_navigation.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/navigation_home"
        android:visible="true"
        android:icon="@drawable/profile_nav_selector"
        android:tooltipText="Profilo"
        android:enabled="true"
        android:title="Profilo" />

    <item
        android:id="@+id/navigation_profile"
        android:visible="true"
        android:icon="@drawable/home_nav_selector"
        android:tooltipText="Veicoli"
        android:enabled="true"
        android:title="Veicoli" />

    <item
        android:id="@+id/navigation_bottle"
        android:icon="@drawable/bottle_nav_selector"
        android:tooltipText="Info"
        android:visible="true"
        android:enabled="true"
        android:title="Info" />

</menu>

fragment_bottle.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/alertWhite"
    tools:context=".fragments.BottleFragment">

    <!-- Home Background -->
    <FrameLayout
        android:layout_width="0dp"
        android:id="@+id/homeBackground"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="140dp"
            android:background="@drawable/oval"
            android:baselineAligned="false"
            android:layout_marginTop="-70dp"
            android:orientation="vertical"
            tools:ignore="MissingConstraints">


            <TextView
                android:id="@+id/hometext"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="80dp"
                android:layout_marginLeft="-10dp"
                android:text="Informazioni"
                android:textSize="20dp" />


        </LinearLayout>


        <ImageView
            android:layout_width="100dp"
            android:layout_height="80dp"
            android:layout_marginTop="70dp"
            android:layout_marginLeft="130dp"
            android:background="@drawable/infobutton"
            tools:ignore="MissingConstraints" />

        <Button
            android:id="@+id/buttonInfoPrivacy"
            android:layout_width="250dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="150dp"
            android:background="@drawable/roundbutton"
            android:layout_marginLeft="60dp"
            android:radius="14dp"
            android:text="Infomativa Privacy"
            android:textColor="#FFFFFF" />

        <Button
            android:id="@+id/buttontermini"
            android:layout_width="250dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="230dp"
            android:background="@drawable/roundbutton"
            android:layout_marginLeft="60dp"
            android:radius="14dp"
            android:text="Termini e Condizioni"
            android:textColor="#FFFFFF" />

        <ImageView
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:layout_marginTop="280dp"
            android:layout_marginLeft="100dp"
            android:background="@drawable/logolive"
            tools:ignore="MissingConstraints" />

        <TextView
            android:id="@+id/txtnumber"
            android:layout_width="100dp"
            android:layout_height="30dp"
            android:layout_alignLeft="@+id/textview"
            android:layout_alignParentBottom="true"
            android:layout_marginTop="430dp"
            android:textColor="#110F0F"
            android:layout_marginLeft="155dp"
            android:textSize="15dp"
            android:textStyle="bold"
            android:text="v. 1.0" />



    </FrameLayout>


</androidx.constraintlayout.widget.ConstraintLayout>

fragment_profile_info.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/alertWhite"
    tools:context=".fragments.ProfileInfoFragment">


    <FrameLayout
        android:id="@+id/frameProfile"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            tools:ignore="MissingConstraints">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="140dp"
                android:background="@drawable/oval"
                android:baselineAligned="false"
                android:layout_marginTop="-70dp"
                android:orientation="vertical"
                tools:ignore="MissingConstraints">

                <ImageView
                    android:id="@+id/buttonlogout"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_marginTop="80dp"
                    android:layout_marginLeft="50dp"
                    android:background="@drawable/iconback" />

                <TextView
                    android:id="@+id/hometext"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="-30dp"
                    android:layout_marginLeft="20dp"
                    android:text="I tuoi veicoli"
                    android:textSize="20dp" />


                <ImageView
                    android:id="@+id/buttonadd"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_marginTop="-26dp"
                    android:layout_marginLeft="270dp"
                    android:background="@drawable/iconadd" />

                <ListView
                    android:id="@+id/list"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:divider="#000"
                    android:layout_marginTop="100dp"
                    android:dividerHeight="1dp"
                    android:footerDividersEnabled="false"
                    android:headerDividersEnabled="false" />


            </LinearLayout>


            <ListView
                android:id="@+id/listView"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />


        </LinearLayout>


    </FrameLayout>


</androidx.constraintlayout.widget.ConstraintLayout>

android – ¿Cómo llamar un Fragment desde un botón en el MainActivity.java?

Estoy intentando hacer un Login, y si el usuario y la contraseña son correctos, llamar un fragment que es la siguiente pantalla a la que el usuario podrá acceder.
El problema es que no se cómo llamar el fragment desde el el MainActivity.java, he investigado mucho y lo que he podido intentar es llamar el método onCreateView() que está en mi clase Fragmento.java pero no sé cuales son los parámetros que le debo pasar al método.

Esta es mi clase Fragment.java


    private OnFragmentInteractionListener mListener;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View vista = inflater.inflate(R.layout.fragment_screen_slide_page, container, false);

        return vista;
    }

    public interface OnFragmentInteractionListener {
        // TODO: Update argument type and name
        void onFragmentInteraction(Uri uri);
    }
}

Este es la parte del MainActivity.java que llama al método onCreateView()

if(email.equals(Euser1)  || email.equals(Euser2) && password.equals(Password)){
           messageOK.show();
           ScreenSlidePageFragment frag = new ScreenSlidePageFragment();
           frag.onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState);
       }else {
           messageF.show();
       }

Espero alguien pueda ayudarme.

opengl – GLSL Help needed to render textures using fragment shader (or procedural textures)

Recently, I have been making a 3D game.
I was messing with my shader files, when I ran into a problem. The “texture” I made for the fragment shader just renders on top of the object, and does not rotate with it or repeat on individual faces, but looks alright when I pass the gl_Vertex colors into gl_FragColor.

Here is the images to tell you what I am talking about
IMG1

While the vertex colors rotate with the object:
IMG2

I am pretty clueless as I’ve never really messed with GLSL shaders at all… I’ve researched a bit but I don’t know what this is called, so I didn’t get any good answers.

Here’s what I know:

  • Fragment shaders mess with all colors on screen and affects colors of specified objects
  • Vertex shaders well, mess with vertex point of the specified object you choose to start the shader for.

Here’s my code for Fragment:

#version 120

uniform float u_time;
uniform vec2 u_resolution;

varying vec4 verpos;

varying vec4 normals;

varying vec4 colors;

in vec2 f_TC;

void main(void)
{
    vec2 st = gl_FragCoord.xy/u_resolution;
    
    // gl_FragColor = vec4(f_TC, 0.0, 1.0);
    
    gl_FragColor = vec4(verpos.xyz, 1.0);
    
    // gl_FragColor = vec4(verpos.xyzw);
    // gl_FragColor = vec4(color, 1.0);
}

And for Vertex:

#version 120

vec4 a = gl_Vertex;
varying vec4 verpos;
varying vec4 normals;
varying vec4 colors;

attribute vec2 in_TC;
out vec2 f_TC;

void main(void) 
{
    // gl_Position = ;

    gl_Position = gl_ModelViewProjectionMatrix * a;
    verpos = gl_Vertex;
    normals = vec4(gl_Normal, 1.0);
    colors = gl_Color;
    f_TC = in_TC;
}

Here is my code to draw the cube:

public void drawCube() throws IOException {
        
        GL11.glBegin(GL11.GL_TRIANGLES);
        // GL11.glColor3f(toRatio(155), toRatio(202), toRatio(222));
        
        //FRONT QUAD
        
        GL11.glTexCoord2f(0, 0);
        GL11.glVertex3f(-10 * x,  10 * x, 10 * x);
        
        GL11.glTexCoord2f(1, 0);
        GL11.glVertex3f(10 * x, 10 * x, 10 * x);
        
        GL11.glTexCoord2f(0, 1);
        GL11.glVertex3f(-10 * x, -10 * x, 10 * x);        
        
        GL11.glTexCoord2f(0, 1);
        GL11.glVertex3f(-10 * x, -10 * x, 10 * x);
        
        GL11.glTexCoord2f(1, 0);
        GL11.glVertex3f(10 * x, 10 *x, 10 * x);
        
        GL11.glTexCoord2f(1, 1);
        GL11.glVertex3f(10 * x, -10 * x, 10 * x);
        
        GL11.glEnd();
        
        GL11.glBegin(GL11.GL_TRIANGLES);
        
        //BACK QUAD
        
        GL11.glTexCoord2f(0, 0);
        GL11.glVertex3f(-10 * x,  10 * x, -10 * x);
        
        GL11.glTexCoord2f(1, 0);
        GL11.glVertex3f(10 * x, 10 * x, -10 * x);
        
        GL11.glTexCoord2f(0, 1);
        GL11.glVertex3f(-10 * x, -10 * x, -10 * x);  
        
        GL11.glTexCoord2f(0, 1);
        GL11.glVertex3f(-10 * x, -10 * x, -10 * x);
        
        GL11.glTexCoord2f(1, 0);
        GL11.glVertex3f(10 * x, 10 *x, -10 * x);
        
        GL11.glTexCoord2f(1, 1);
        GL11.glVertex3f(10 * x, -10 * x, -10 * x);
        
        GL11.glEnd();
        
        GL11.glBegin(GL11.GL_TRIANGLES);
        
        //LEFT QUAD
        GL11.glTexCoord2f(0, 0);
        GL11.glVertex3f(-10 * x, 10 * x, -10 * x);
        
        GL11.glTexCoord2f(1, 0);
        GL11.glVertex3f(-10 * x, 10 * x, 10 * x);
        
        GL11.glTexCoord2f(0, 1);
        GL11.glVertex3f(-10 * x, -10 * x, -10 * x);
        
        GL11.glTexCoord2f(0, 1);
        GL11.glVertex3f(-10 * x, -10 * x, -10 * x);
        
        GL11.glTexCoord2f(1, 0);
        GL11.glVertex3f(-10 * x, 10 * x, 10 * x);
        
        GL11.glTexCoord2f(1, 1);
        GL11.glVertex3f(-10 * x, -10 * x, 10 * x);
        
        GL11.glEnd();
        
        GL11.glBegin(GL11.GL_TRIANGLES);
        
        //RIGHT QUAD
        
        GL11.glTexCoord2f(0, 0);
        GL11.glVertex3f(10 * x, 10 * x, 10 * x);
        
        GL11.glTexCoord2f(1, 0);
        GL11.glVertex3f(10 * x, 10 * x, -10 * x);
        
        GL11.glTexCoord2f(0, 1);
        GL11.glVertex3f(10 * x, -10 * x, 10 * x);
        
        GL11.glTexCoord2f(0, 1);
        GL11.glVertex3f(10 * x, -10 * x, 10 * x);
        
        GL11.glTexCoord2f(1, 0);
        GL11.glVertex3f(10 * x, 10 * x, -10 * x);
        
        GL11.glTexCoord2f(1, 1);
        GL11.glVertex3f(10 * x, -10 * x, -10 * x);
        
        GL11.glEnd();
        
        GL11.glBegin(GL11.GL_TRIANGLES);
        
        //TOP QUAD
        
        //debugColor();
        
        GL11.glTexCoord2f(0, 0);
        GL11.glVertex3f(-10 * x,  10 * x, -10 * x);
        
        GL11.glTexCoord2f(1, 0);
        GL11.glVertex3f(10 * x,  10 * x, -10 * x);
        
        GL11.glTexCoord2f(0, 1);
        GL11.glVertex3f(-10 * x,  10 * x, 10 * x);
        
        GL11.glTexCoord2f(0, 1);
        GL11.glVertex3f(-10 * x, 10 * x, 10 * x);
        
        GL11.glTexCoord2f(1, 0);
        GL11.glVertex3f(10 * x, 10 * x, -10 * x);
        
        GL11.glTexCoord2f(1, 1);
        GL11.glVertex3f(10 * x, 10 * x, 10 * x);
        
        GL11.glEnd();
        
        GL11.glBegin(GL11.GL_TRIANGLES);
        
        //BOTTOM QUAD
        
        GL11.glTexCoord2f(0, 0);
        GL11.glVertex3f(-10 * x,  -10 * x, -10 * x);
        
        GL11.glTexCoord2f(1, 0);
        GL11.glVertex3f(10 * x,  -10 * x, -10 * x);
        
        GL11.glTexCoord2f(0, 1);
        GL11.glVertex3f(-10 * x,  -10 * x, 10 * x);
        
        GL11.glTexCoord2f(0, 1);
        GL11.glVertex3f(-10 * x, -10 * x, 10 * x);
        
        GL11.glTexCoord2f(1, 0);
        GL11.glVertex3f(10 * x, -10 * x, -10 * x);
        
        GL11.glTexCoord2f(1, 1);
        GL11.glVertex3f(10 * x, -10 * x, 10 * x);
        
        
        GL11.glEnd();
        
    }

My code to load images:

package me.pale.texture;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.newdawn.slick.opengl.*;

public class IMG {
    
    Texture texture;
    
    public IMG (String file) {
        
        try {
            texture = TextureLoader.getTexture("PNG", new FileInputStream("res/" + file + ".png"));
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
        texture.bind();
        
    }

    public Texture getTexture() {
        return texture;
    }

}

And here’s my entire MainLoop class:

package me.pale.main;

import java.io.File;

import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL20;
import org.lwjgl.util.glu.GLU;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import org.newdawn.slick.util.ResourceLoader;

import me.pale.input.Input;
import me.pale.model.Model;
import me.pale.model.RGB;
import me.pale.shader.RegShader;

public class MainLoop extends RGB{
    
    float a = 0;
    
    float() verts = new float() {
            
        0.0f, 0.5f, 0.0f,
        -0.5f, -0.5f, 0.0f,
        0.5f, -0.5f, 0.0f
            
    };
    
    String vertex = "res/vertex.txt";
    String frag = "res/fragment.txt";
    
    File vertexShad = new File(this.getClass().getResource("/vertex.glsl").toString());
    File fragShad = new File(this.getClass().getResource("/fragment.glsl").toString());
    
    float rot = 0;
    float DX = 0;
    float DY = 0;
    
    Input i = new Input();
    
    RegShader shader;
    
    Model cube = new Model();
    
    Texture tex;
    
    public void init() throws LWJGLException, Exception {
        

        Display.setDisplayMode(new DisplayMode(640, 480));
        Display.create();
        
        shader = new RegShader();
        
        tex = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/test.png"));
        
        Display.sync(60);
        
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glLoadIdentity();
        // GL11.glOrtho(-640/2, 640/2, -480/2, 480/2, -200, 500);
        
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
        
        GL11.glClearColor(0, 0, 0, 0);
        
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_LIGHTING);
        
        GL11.glEnable(GL11.GL_NORMALIZE);
        //GL11.glEnable(GL11.GL_BLEND);
        //GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        
        GLU.gluPerspective(90.0f, 1.333f, 1.0f, 650.0f);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        
        GL11.glEnable(GL11.GL_DEPTH_TEST);
        GL11.glDepthMask(true);
        GL11.glDepthFunc(GL11.GL_LESS);
        GL11.glLoadIdentity();
        
        GL11.glTranslatef(0.0f, 0.0f, -500.0f);
        
        tex.bind();
        
        while (!Display.isCloseRequested()) {
            
            // Clear the screen and depth buffer
            // GL11.glEnable(GL11.GL_DEPTH_TEST);
            GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);  
            
            GL11.glClearColor(1.0f, 1.0f, 0.2f, 1.0f);
             
            // set the color of the quad (R,G,B,A)
            // GL11.glColor3f(toRatio(12), toRatio(202), toRatio(222));
            input();
            
            shader.start();
            
            a+=0.001f;
            
            if (a > 360) {
                a = 0;
            }
            
            int uniform1 = GL20.glGetUniformLocation(shader.getProgID(), "u_time");
            
            GL20.glUniform1f(GL20.glGetUniformLocation(shader.getProgID(), "u_time"), a);
            
            int res = GL20.glGetUniformLocation(shader.getProgID(), "u_resolution");
            
            GL20.glUniform2f(GL20.glGetUniformLocation(shader.getProgID(), "u_resolution"), 640.0f, 480.0f);
            
            GL11.glPushMatrix();
            
            GL11.glRotatef(DX += Mouse.getDX(), 0, 1, 0);
            GL11.glRotatef(DY += Mouse.getDY(), 1, 0, 0);
            
            // GL11.glRotatef(rot += 0.05f, 1, 1, 1);
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex.getTextureID());
           
            cube.drawCube();
            
            GL11.glLoadIdentity();
            
            GL11.glPopMatrix();
            
            shader.halt();
            
            Display.update();
            
        }
        
        shader.wash();
        Display.destroy();
        
    }
    
    public void input() {
        
        if (Keyboard.getEventKey() == Keyboard.KEY_A) {
            
            if (Keyboard.getEventKeyState()) {
                
                GL11.glTranslatef(0.3f, 0, 0);
                
            }
            
        }
        if (Keyboard.getEventKey() == Keyboard.KEY_D) {
            
            if (Keyboard.getEventKeyState()) {
                
                GL11.glTranslatef(-0.3f, 0, 0);
                
            }
            
        }
        if (Keyboard.getEventKey() == Keyboard.KEY_W) {
            
            if (Keyboard.getEventKeyState()) {
                
                GL11.glTranslatef(0, 0, 0.3f);
                
            }
            
        }
        if (Keyboard.getEventKey() == Keyboard.KEY_S) {
            
            if (Keyboard.getEventKeyState()) {
                
                GL11.glTranslatef(0, 0, -0.3f);
                
            }
            
        }
        
        if (i.isLMBDown()) {
            
            System.out.println("MOUSEX: " + i.getMouseX() + ", MOUSEY: " + i.getMouseY());
            
        }
        
        while (Keyboard.next()) {
            
            if (Keyboard.getEventKey() == Keyboard.KEY_B) {
                
                if (Keyboard.getEventKeyState()) {
                    
                    System.out.println("Key B Pressed.");
                    
                }
                
            }
            
            if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) {
                
                Display.destroy();
                System.exit(0);
                
            }
            
        }
        
    }
    
    public static void main(String() args) throws Exception {
        
        MainLoop ml = new MainLoop();
        ml.init();
        
    }

}

Any help appreciated

Yes, I am using old methods and no VBOs and VAOs

I grabbed some code from This Link to help with trying to render textures but it wont work.

The main thing I need is how to grab the texture coordinates. The texcoords are declared in the model using GL11.glTexCoord2f();, not using Arraylists

~ Pale_Gray

java – How to add Vertex and Fragment shaders using the old depreciated methods in LWJGL 2?

Recently, I am trying to make a 3D game in LWJGL 2, not LWJGL 3, just because I am more familiar with LWJGL 2. Since LWJGL decided to shut down their legacy wiki website, I’ve been researching alot lately on adding shaders. The thing is, most of these tutorials use VBOs and VAOs to render objects.

I am trying to use vertex and fragment shaders to edit the objects. Yes, I am using the depreciated methods glBegin(); and those rendering methods to draw shapes. I am not sure if this affects the use of shaders or not, so that is why I am asking this question.

If anyone wants to know, I am using the depreciated methods because I don’t want to really use VAOs and VBOs, I know it reduces performance to use the depreciated methods, but I am fine with this for now.

If anyone can help, much appreciated!

java – OpenGL Compute Shader vs Fragment Shader device support

I have a game with massively parallelizable logic, which I intend to write calculate on the GPU (Java/LibGDX).

I am planning to implement a logic for it through a fragment shader, instead of a compute shader because I have the intuition that Fragment shaders supported on more devices, than compute shaders.

Is this even true? Given all other variables eliminated, are fragment shaders available on more devices, than compute shaders? Or in openGLES(desktop, android, ios) compute shaders are always available anyway?

What restrictions are in effect here?

DreamProxies - Cheapest USA Elite Private Proxies 100 Cheapest USA Private Proxies Buy 200 Cheap USA Private Proxies 400 Best Private Proxies Cheap 1000 USA Private Proxies 2000 USA Private Proxies 5000 Cheap USA Private Proxies ExtraProxies.com - Buy Cheap Private Proxies Buy 50 Private Proxies Buy 100 Private Proxies Buy 200 Private Proxies Buy 500 Private Proxies Buy 1000 Private Proxies Buy 2000 Private Proxies ProxiesLive.com Proxies-free.com New Proxy Lists Every Day Proxies123.com Proxyti.com Buy Quality Private Proxies